zoukankan      html  css  js  c++  java
  • 将list中的元素按照属性分类成树状的map

    技术交流群: 233513714


    public LinkedHashMap<String, List<TPhoneModel>> queryPhoneList(List<TPhoneModel> list) { LinkedHashMap<String, List<TPhoneModel>> map = new LinkedHashMap<>(); for (TPhoneModel li : list) {
            //将需要归类的属性与map中的key进行比较,如果map中有该key则添加bean如果没有则新增key
    if (map.containsKey(li.getAnotherName())) {
            //取出map中key对应的list并将遍历出的bean放入该key对应的list中 ArrayList
    <TPhoneModel> templist = (ArrayList<TPhoneModel>) map.get(li.getAnotherName()); templist.add(li); } else {
            //创建新的list ArrayList
    <TPhoneModel> temlist = new ArrayList<TPhoneModel>(); temlist.add(li); map.put(li.getAnotherName(), temlist); } } return map; }
  • 相关阅读:
    MongoDb
    js暴露内部方法属性等
    JS闭包
    k8s设计模式
    scrum
    死锁
    Linux下安装php 扩展fileinfo
    linux中whereis、which、find、location的区别和用法
    Linux 命令学习记录
    windows 下 redis 的安装及使用
  • 原文地址:https://www.cnblogs.com/cnndevelop/p/6373097.html
Copyright © 2011-2022 走看看