- List 转Map
Map<Long, User> map = list.stream().collect(Collectors.toMap(User::getId, Function.identity(), (key1, key2) -> key2));
Map<Long, String> map = list.stream().collect(Collectors.toMap(User::getId, User::getAge, (key1, key2) -> key2));
- list对象中属性进行分组
Map<Integer, List> map = list.stream().collect(Collectors.groupingBy(User::getId));
- list对象的属性组装成list
List<Long> list= list.stream().map(Device::getId())collect(Collectors.toList())
- list对象属性的排序、
7.List获取最大值
Optional<Integer> max=list.stream().max(Comparator.comparing(Integer::intValue())).orElse(0)
max.get();