Lambda表达式中针对List的常用方法

 

  • List =>Map
Map map = list1.stream().collect(Collectors.toMap(People::getName, people -> people));
  •  
  • List 分组
Map> mapList = list1.stream().collect(Collectors.groupingBy(People::getName));
  •  
  • List 排序 – 从低到高
list1.sort((p1, p2) -> p1.getAge() - p2.getAge());
  • List 多条件排序 – 先按照年龄,再按照身高
list1.sort(Comparator.comparing(People::getAge).thenComparing(People::getHeight));

你可能感兴趣的:(Lambda表达式中针对List的常用方法)