美文网首页
remove 掉list中的数据

remove 掉list中的数据

作者: 酷酷的美猴王 | 来源:发表于2018-09-14 12:10 被阅读0次

list中的数据是基本数据类型的,比如List<Integer> 、List<String>。。。的可以直接remove
但list中的数据是对象的,要根据id去remove,比如List<User> users 则 要写hashCode

@Data
public class OpenList implements Serializable {
        private Long id;
        private String name;
        
    @Override
    public int hashCode() {
        int result = 31 *(id != null ? id.hashCode() : 0);
        return result;
    }
}

然后users.remove(user);

相关文章

网友评论

      本文标题:remove 掉list中的数据

      本文链接:https://www.haomeiwen.com/subject/tqcogftx.html