importjava.util.*;publicclassMain{publicstaticvoidmain(String[]args){HashMaptest1=newHashMap();test1.put("GN","1.1.1");test1.put("E212","1");test1.put("INCTYPE","新增");test1.put("ID","1");HashMaptest2=newHashMap();test2.put("GN","2.2.2");test2.put("E212","2");test2.put("INCTYPE","新增");test2.put("ID","2");HashMaptest3=newHashMap();test3.put("GN","2.2.2");test3.put("E212","1");test3.put("INCTYPE","删除");test3.put("ID","3");HashMaptest4=newHashMap();test4.put("GN","3.3.3");test4.put("E212","3");test4.put("INCTYPE","删除");test4.put("ID","4");HashMaptest5=newHashMap();test5.put("GN","4.4.4");test5.put("E212","4");test5.put("INCTYPE","删除");test5.put("ID","5");HashMaptest6=newHashMap();test6.put("GN","4.4.4");test6.put("E212","5");test6.put("INCTYPE","新增");test6.put("ID","6");HashMaptest7=newHashMap();test7.put("GN","4.4.4");test7.put("E212","5");test7.put("INCTYPE","删除");test7.put("ID","7");HashMaptest8=newHashMap();test8.put("GN","4.4.4");test8.put("E212","4");test8.put("INCTYPE","删除");test8.put("ID","8");MapstdMap=newHashMap();Listlist=newArrayList();list.add(test1);list.add(test2);list.add(test3);list.add(test4);list.add(test5);list.add(test6);list.add(test7);list.add(test8);//Listlist2=list;//Listlist3=newArrayList();System.out.println(list);for(Mapmap:list){if(stdMap.size()==0){Stringrealm=map.get("ID")==null?"":map.get("ID").toString();stdMap.put(realm,map);}Iteratoriter=stdMap.entrySet().iterator();booleanflag=true;while(iter.hasNext()){Map.Entryentry=(Map.Entry)iter.next();Mapval=(Map)entry.getValue();if(map!=val&&map.get("E212").equals(val.get("E212"))){if((map.get("INCTYPE").equals("新增")&&val.get("INCTYPE").equals("删除"))||(map.get("INCTYPE").equals("删除")&&val.get("INCTYPE").equals("新增"))){iter.remove();flag=false;}}}if(flag){Stringrealm=map.get("ID")==null?"":map.get("ID").toString();stdMap.put(realm,map);}}System.out.println(stdMap);}}改了一下,现在成了这样,请问还能优化一下吗 |