lambda表达式
1、list 循环及过滤
List<UserDTO> a = list.stream().peek(dto->{
if("a".equals(dto.getName())) {
dto.setName("aa");
dto.setDescription(22);
}
System.out.println(dto);
}).filter(dto->!dto.getName().equals("b")).collect(Collectors.toList());
2、list排序
List<UserDTO> a = list.stream().peek(dto->{
if("a".equals(dto.getName())) {
dto.setName("aa");
dto.setDescription("22");
}
System.out.println(dto);
}).sorted(Comparator.comparing(UserDTO::getDescription)).collect(Collectors.toList());
3、String 转 List<Integer>
List<Integer> listInt = Arrays.stream(orderIds.split(","))
.mapToInt(Integer::parseInt).boxed().collect(Collectors.toList());
listInt.forEach(System.out::println);
3. 逗号拼接字符串
faultModeNameSet.stream().map(String::valueOf).collect(Collectors.joining(","));