对list进行分类

Posted ycr19921121

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了对list进行分类相关的知识,希望对你有一定的参考价值。

/**
 * 对按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;

以上是关于对list进行分类的主要内容,如果未能解决你的问题,请参考以下文章