java 8 流的简单记录

// 多条件组合排序:
List humans = Lists.newArrayList(
        new Human("Sarah", 12), new Human("Sarah", 10), new Human("Zack", 12));
humans.sort(Comparator.comparing(Human::getName).thenComparing(Human::getAge));


// groupingBy (3个参数) key - TreeMap - value:默认是 hashMap
TreeMap> matchsListMap = matchsList.stream()
.collect(Collectors.groupingBy(Matchs::getMatchDate,TreeMap::new,Collectors.toList()));

// groupingBy (1个参数) 提取Key, 默认的 value 是本身满足条件的数据的List
Map> matchsListMap  = matchsList.stream()
.collect(Collectors.groupingBy(Matchs::getMatchDate));

// groupingBy (2个参数) 提取 Key - value,
Map> matchsListMap  = matchsList.stream()
.collect(Collectors.groupingBy(Matchs::getMatchDate, Colloctors.counting()));

 

你可能感兴趣的:(java 8 流的简单记录)