有的时候我们有这样的需求,在一个集合中有几个对象的数据是重复的,我们只想取不重复的那几个,可以通过以下方法去做
//这里讲述的是通过tDeptId这个字段去重
private static <T> Predicate<T> distinctByVariable(Function<? super T, ?> keyExtractor){
HashMap<Object, Boolean> map = new HashMap<>();
return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
public HttpResult updateUserInfo(@RequestBody UpdateUserParam updateUserParam) {
List<UpdateDeptCheckParam> collect3 = collect.stream().filter(distinctByVariable(u -> u.getDeptId())).collect(Collectors.toList());
}
版权声明:本文为weixin_59244784原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。