Bootstrap

Stream根据多个字段去重

分组:

list.stream().collect(Collectors.groupingBy(ClassEntity::getGrade));

java8有一个collectingAndThen可以根据多个字段去重

list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getProfessionId() + ";" + o.getGrade()))), ArrayList::new));

通过hashSet去重:该种去重是bean完全相同的时候算重复数据

List<String> classNameList = new ArrayList(new HashSet(list));

;