/** * 按照指定字段给list去重 * @param list * @return */ public static List<DataModel> niqueList(List<DataModel> list){ //去重,根据code字段 List<DataModel> uniqueList = list.stream().collect( collectingAndThen( toCollection(() -> new TreeSet<>(comparing(n->n.getCode()))), ArrayList::new) ); return uniqueList; }
list java8 按照指定元素去重