首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-08-28 
遍历List按照类型分类组装map对象??? private MapString, ListA getMap(ListA a,ListB b)??? ???

遍历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;
??? }

热点排行