遍历List 按照类型分类组装map对象

    private Map<String, List<A>> getMap(List<A> a,List<B> b)
            throws SQLException {
     
        Map<String,List<A>> retmap = new HashMap<String,List<A>>();
       
        Map midMap1 = new HashedMap();
       
        for (A obj : a) {
             
            midMap1.put("K_"+obj.getId(), obj);
        }
       
       
        for (B obj : b) {
             
            if(midMap1.get("K_"+obj.getId())!=null)
            {
           
               
                if(retmap.get(""+obj.getType()) ==null)
                {
                    retmap.put( ""+obj.getType(), new ArrayList());
                }
                List ls = (ArrayList)retmap.get(""+obj.getType());
                ls.add(midMap1.get("K_"+obj.getId())) ;
                retmap.put(""+obj.getType(), ls);
            }
        }
       
       
        return retmap;
    }

你可能感兴趣的:(list,map,HashMap,ArrayList)