toList List<T>
把流中所有元素收集到List中
示例:List<Menu> menus=Menu.getMenus.stream().collect(Collectors.toList())
Joining String
连接流中每个元素的toString方法生成的字符串
示例:String name=Menu.getMenus.stream().map(Menu::getName).collect(joining(“, ”))
maxBy Optional<T>
一个包裹了流中按照给定比较器选出的最大元素的optional
如果为空返回的是Optional.empty()
示例:Optional<Menu> fattest=Menu.getMenus.stream().collect(maxBy(Menu::getCalories))
groupingBy Map<K,List<T>>
根据流中元素的某个值对流中的元素进行分组,并将属性值做为结果map的键
Map<String, List<Person>> resultMap = personList.stream().collect(Collectors.groupingBy(c -> c.getAddress()));
filter 过滤
List<Apple> filterList = appleList.stream().filter(a -> a.getName().equals("香蕉")).collect(Collectors.toList());
mapreduce 求和
BigDecimal totalMoney = appleList.str