java8 list 处理:
参数传递:
() -> 5
x -> 2 * x
(x, y) -> x – y
(int x, int y) -> x + y
(String s) -> System.out.print(s)
1. 指定字段去重:
ts.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(()->new TreeSet<>(Comparator.comparing(Test::getName))),ArrayList::new))
2. 指定多个字段去重:
ts.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(()->new TreeSet<>(Comparator.comparing(Test::getName))),ArrayList::new
));
3. list转map:
ts.stream().collect(Collectors.toMap(e->e.getName(),e->e));
4. 条件过滤:
List<Test> list = ts.stream()
.filter(e -> (e.getName() != null && e.getName().startsWith("张")))
.filter(e->(e.getAge() >=18 && e.getAg