lambda表达式:
1、获取对象list其中一个属性放进List
List<String> Ids = newList.stream().map(UserInfoDto::getId).collect(Collectors.toList());
2、获取对象list,其中一个唯一属性放进Map
Map<String, UserInfoDto> userMap = userList.stream().collect(Collectors.toMap(UserInfoDto::getId, userInfoDto -> userInfoDto));
3、取2个List的交集
List<UserInfoDto> newList = restList.stream().filter(item -> userList.stream().map(UserInfoDto::getId).collect(Collectors.toList()).contains(item.getId())).collect(Collectors.toList());
4、过滤对象list其中一个属性符合条件的属性放进List
List<String> ids = newList.stream()..filter(c -> !c.getFirstName.equals("吴")).collect(Collectors.toList());
result = result.stream().filter(a -> a.getStatue().equals("01) && a.getAge() >= 10).collect(Collectors.toList());
5、排序场景对象List按照一个对象其中一个属性排序
result.sort((h1, h2) -> h1.getTimePoint().compareTo(h2.getTimePoint()));
6、根据对象List其中某一个属性分组汇总成Map<String,List>
Map<String, List<TestDto>> map = result.stream().collect(Collectors.groupingBy(TestDto::getTimePoint));
Map<String, List<String>> newMap = new HashMap<>();
for (Map.Entry<String, List<TestDto>> entry : map.entrySet()) {
newMap.put(entry.getKey(), entry.getValue().stream().map(TestDto::getType).collect(Collectors.toList()));
}
7、根据对象List其中某一个属性分组汇总成Map<String,List>
Map<String, List<TestDto>> map = result.stream().collect(Collectors.groupingBy(TestDto::getTimePoint));
8、Map<String,List> 根据key排序
newMap.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEachOrdered(x -> resultMap.put(x.getKey(), x.getValue()));