package com.itheima.method2;
import java.util.*;
import java.util.stream.Collectors;
import static com.itheima.test.Test1.printArray;
public class Test007 {
public static void main(String[] args) {
//System.out.println(chengji(new int[]{-8,-1,1, 3, 4}));
// 2.3 数据去重
List<Student> functionList = Arrays.asList(
new Student(123, "分组1", "2019-12-11"),
new Student(124, "分组1", "2019-12-23"),
new Student(125, "分组2", "2020-12-11"),
new Student(126, "分组2", "2020-12-23"));
ArrayList<Student> collect = functionList.stream().
sorted(Comparator.comparing(Student::getAddress).reversed())
.collect(Collectors.
collectingAndThen(Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(Student::getName))), ArrayList::new));
System.out.println(collect);
}
public static int jieCheng(int n){
if (n==1){
return 1;
}
return n*jieCheng(n-1);
}
}
Stream中的collectingAndThen去重排序(取每组日期最大)
于 2024-02-13 17:43:15 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)