3、调用TreeUtils工具类 在服务层调用TreeUtils工具类,一行代码完成转换。 publicList<TreeNode<String>>selectCategoryList2(){List<Category>list=this.list();// 一行代码实现列表转树结构 通用型代码 能够跨项目使用 业务解藕returnTreeUtils.createNode(list,"000000");} 1. 2. 3. 4. 5. 4、效果展示 ...
TreeMap<String, List<User>> treeMap =userList.stream() .sorted((o1, o2)-> o1.getAge() -o2.getAge()) .collect(groupingBy(item-> item.getHeight, TreeMap::new, toList())); //lambda优雅取出对象list中某个属性重复的集合数据:publicclassTest {//https://blog.csdn.net/qq_35902833/artic...
1.6list根据条件去重过滤 List<ResourceHighFile> highFiles = new ArrayList<>(); Set<ResourceHighFile> set =newTreeSet<ResourceHighFile>((file1, file2) ->file1.getFileName().compareTo(file2.getFileName())); set.addAll(highFiles); //根据getName去重 personList= personList.stream().collect...
List<String>copyOnWriteArrayListResult = list.stream().collect(Collectors.toCollection(CopyOnWriteArrayList::new)); copyOnWriteArrayListResult.forEach(System.out::println); System.out.println("---"); //用TreeSet收集 TreeSet<String>treeSetResult = list.stream().collect(Collectors.toCollection(TreeSet::...
//根据编号去重List<EquipmentDto>resultList=list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->newTreeSet<>(Comparator.comparing(EquipmentDto::getNumber))),ArrayList::new)); 6.提取 //提取编号List<Integer>numberList=list.stream().map(EquipmentDto::getNumber)//流转化为In...
*/ArrayList<Users>collect=addModel().stream().collect(collectingAndThen(toCollection(()->newTreeSet<>(comparing(Users::getId))),ArrayList::new));System.out.println("==="+JSON.toJSONString(collect));}publicvoiddistictUniq(){List<Users>collect=addModel().stream().filter(distinctByKey(...
import static java.util.stream.Collectors.toCollection; // 根据id去重 List<Person> unique = appleList.stream().collect( collectingAndThen( toCollection(() -> new TreeSet<>(comparingLong(Apple::getId))), ArrayList::new) ); 下表展示 Collectors 类的静态工厂方法。 来源:...
buildTree(rootNode, map); return rootNode; } private void buildTree(Node currentNode, Map<String, List<String>> map) { List<Node> children = map.get(currentNode.getValue()).stream() .map(s -> new Node(s, new ArrayList<>())) ...
三、list转树形方法 public static List<NodeVO> streamToTree(List<NodeVO> treeList, String parentId) { List<NodeVO> list = treeList.stream() // 过滤父节点 .filter(parent -> parent.getPid().equals(parentId)) // 把父节点children递归赋值成为子节点 ...
toList()); // 获取所有的name转换到Set<String>中 Set<String> set = people.stream().map(Person::getName).collect(Collectors.toCollection(TreeSet::new)); // 元素转换为String 并且将他们通过", " 连接起来 String joined = things.stream() .map(Object::toString) .collect(Collectors.joining("...