根据指定对象的属性值对集合进行去重
public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
return object -> seen.putIfAbsent(keyExtractor.apply(object), Boolean.TRUE) == null;
}
public static void main(String[] args) {
List<PlanDeviceDO> list = new ArrayList<>();
list.add(new PlanDeviceDO().setDeviceInfoId("1").setDeviceInfoName("jj"));
list.add(new PlanDeviceDO().setDeviceInfoId("1").setDeviceInfoName("ccjj"));
list.add(new PlanDeviceDO().setDeviceInfoId("2").setDeviceInfoName("vvjj"));
list = list.stream().filter(distinctByKey(PlanDeviceDO::getDeviceInfoId)).collect(Collectors.toList());
System.out.println(list);
}