1、对list进行去重
(1)对list去重 : List unique = list.stream().distinct().collect(Collectors.toList());
(2)对list对象根据一个字段去重 : List<Order> orderList = orders.stream().collect(Collectors.collectingAndThen(Collectors.toCollection() -> new TreeSet<>(Comparator.comparing(Order::getId))),ArrayList::new);
(3)对list对象根据两个字段去重 : List<Order> orderList = orders.stream().collect(Collectors.collectingAndThen(Collectors.toClooection() -> new TreeSet<>(Comparator.comparing(o->o.getId+";"+o.getstatus()))),ArrayList::new);
2、根据某个值过滤list对象
List<Order> filterList = orders.stream().filter(o ->o.getId().equals("2019020102")).collect(Collectors.toList());
3、list转Map,取出id和name组成map集合
Map <String,String> map = list.stream().collect(Collectors.toMap(s -> s.getId(),s => s.getName()));
4、从list中取出某个属性组成list集合
List<String> idList = list.stream().map(Schedule::getId).collect(Collectors.toList());
5、从list中取出某个属性并去重组成list集合
List<String> idList = list.stream().map(Schedule::getId).distinct().collect(Collectors.toList());
6、排序、按Id升序排列,若要降序,则改为:(a, b) -> b.getId() - a.getId(); a、b为变量名,随便写
List<Labroom> sortList = list.stream().sorted((a,b) ->a.getId() - b.getId()).collect(Collectors.toList());
7、按照条件过滤符合要求的数据,组成新的list
List<Student> stuList = list.stream().filter(s -> s.getScore() < 60).collect(Collectors.toList());
8、获取某个list对象中某个属性的集合
List<Sting> newList = list.stream().map(t -> t.getName()).collect(Collectors.toList());
9、统计list的sum和
double sum = list.stream().mapToDouble(t -> t.getScore()).sum();
10、分组
(1)按照字段中某个属性对list进行分组 : Map<Integer,List<Schedule>> map = list.stream().collect(Collectors.groupingBy(t -> t.getGrade()));
(2) 多字段分组 : Map<Integer,List<Schedule>> map = list.stream().collect(Collectors.groupingBy(t -> t.getGrade(),Collectors.groupingBy(t -> t.getClasses())));
(3)多字段分组统计(统计每个年级、每个班的总分数) : Map<Integer,Map<Integer,Double>> sumMap = list.stream().collect(Collectors.groupingBy(t -> t.getGrade(),Collectors.groupingBy(t -> t.getClasses(),Collectors.summingDouble(t -> t.getScore()))));
11、统计每个年级、每个班的及格人数
Map<Integer,Map<Integer,Long>> integerMap = list.stream().filter(t -> t.getScore() >= 60).collect(Collectors.groupingBy(t -> t.getGrade(),Collectors.groupingBy(t -> t.getClasses(),Collectors.counting())));
12、1.8中的for循环
numList.forEach((num) -> system.out.printIn(num));