@Override public String toString() { return"Student [name=" + name + ", sno=" + sno + ", sex=" + sex + "]"; }
}
根据sno字段去重
1 2 3 4 5 6 7 8 9 10 11
List<Student> list = new ArrayList<Student>();
for (int i = 0; i < 3; i++) { list.add(new Student("123", "name", i)); }
list = list.stream().collect( Collectors.collectingAndThen( Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Student::getSno))), ArrayList::new));