/**
* arraysLists 取出id转成String集合
*/
List<Integer> integerList = listUsers.stream().map(User::getAge).collect(Collectors.toList());
System.out.println("[取出id转成String集合]:"+integerList);
/**
* arraysLists 去重
*/
List<User> distanctList = listUsers.stream().distinct().collect(Collectors.toList());
System.out.println("[arraysLists 去重]:"+distanctList);
/**
* 处理 list对象 分组 转成list
* 并且并行 处理数据
*/
List<List<User>> partitionList = Lists.partition(listUsers,2);
System.out.println(partitionList);
List<User> parallelList = partitionList.parallelStream().map(model->{
System.out.println("当前处理业务线程为:"+Thread.currentThread().getName());
return model;
}).flatMap(Collection::stream).collect(Collectors.toList());
System.out.println("[处理 list对象 分组 转成list]:"+parallelList);
/**
* 处理 对象 转成map
*/
Map<Integer, String> map =listUsers.stream().collect(Collectors.toMap(User::getAge,User::getName));
System.out.println("[处理 对象 转成map]:"+map);
List<MenuDto> childrenMenuList = childrenMenuEntityList.stream().map(e -> this.convertMenuEntityToDto(e, allMenuEntityList, allButtonEntityList, buttonEntityMap)).collect(Collectors.toList());
jdk1.8中parallelStream流并行处理
于 2021-03-24 17:04:52 首次发布