// 创建一个包含DeptEntity对象的List,并向其中添加若干元素 ListdeptEntityList= new ArrayList<>(); deptEntityList.add(new DeptEntity(1, '部门1')); deptEntityList.add(new DeptEntity(1, '部门1')); deptEntityList.add(new DeptEntity(2, '部门2')); // 使用java8的stream流进行元素去重(根据DeptEntity中的id进行元素去重) ArrayList disList = deptEntityList.stream().collect( Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(DeptEntity::getId))), ArrayList::new))



