public class Demo {
public static void main(String[] args) throws IOException {
Student s1 = new Student(1L, "a", 18);
Student s2 = new Student(2L, "b", 19);
Student s3 = new Student(3L, "c", 20);
Student s4 = new Student(4L, "a", 13);
Student s5 = new Student(5L, "a", 18);
List<Student> list = Arrays.asList(s1, s2, s3, s4, s5);
list = list.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(
() -> new TreeSet<>(Comparator.comparing(e ->
e.getName() + "#" + e.getAge()
))
), ArrayList::new)
);
list.forEach(System.out::println);
}
}
文章评论