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(","));

 

posted @ 2020-03-05 11:06  jack_zou2018  阅读(182)  评论(0编辑  收藏  举报