首页 > 编程语言 >java8特性-list集合根据多个字段去重

java8特性-list集合根据多个字段去重

时间:2022-12-19 17:14:05浏览次数:52  
标签:Collectors list 字段 集合 new java8

//按专业和年级去重,专业和年纪一样时表示重复对象

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

标签:Collectors,list,字段,集合,new,java8
From: https://www.cnblogs.com/wj123bk/p/16992587.html

相关文章