List 过滤
List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
List<String> filtered = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());
List 转map
Map<String, String> map = list.stream().collect(Collectors.toMap(Area::getName,Area::getCode, (e1, e2) -> e1)); Map<String,List<CityDto>> pcMap = cityList.stream().collect(Collectors.groupingBy(CityDto::getProvinceName));
统计
List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
IntSummaryStatistics stats = numbers.stream().mapToInt((x) -> x).summaryStatistics(); System.out.println("列表中最大的数 : " + stats.getMax());
System.out.println("列表中最小的数 : " + stats.getMin());
System.out.println("所有数之和 : " + stats.getSum()); System.out.println("平均数 : " + stats.getAverage());
记录下来~有需要查看