对list进行分类

来源:互联网 发布:c语言进制转换程序 编辑:程序博客网 时间:2024/05/16 17:20
/** * 对按ip缩容的容器列表按分组分类 * 返回的数据结构为 * key :  分组1  value: [obj,obj,obj] * @param list * @return */public Map<String,Integer> sortIps(List<DestroyItem> list){    TreeMap tm=new TreeMap();    if(CollectionUtils.isNotEmpty(list)){        for (DestroyItem item:list) {            //如果包含key            if(tm.containsKey(item.getAppGroup())){                ArrayList currentList=(ArrayList)tm.get(item.getAppGroup());                currentList.add(item);            }else{                ArrayList itemList=new ArrayList();                itemList.add(item);                tm.put(item.getAppGroup(), itemList);            }        }    }    return tm;}