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(p->p.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
.filter(e -> (e.getName() != null && e.getName().startsWith("张")))
.filter(e->(e.getAge() >=18 && e.getAge()<=100))
.collect(Collectors.toList());
5. 是否包含与包含几个:
boolean is_l = ts.stream().anyMatch(e -> e.getName().equals("李四")); // allMatch , anyMatch
long count_l = ts.stream().filter(e -> e.getName().equals("李四")).count();
6. 取某几个字段封装为list:
List



