Map key和value都比对





原文见http://bbs.csdn.net/topics/370185446

public static void main(String[] args) {
  /**
   * 比对map1和map2中key和value内容的不同。
   */
  Map<String, String> mapA = new HashMap<String, String>();
  Map<String, String> mapB = new HashMap<String, String>();
  Map<String, String> mapAdd = new HashMap<String, String>(mapB);
  Map<String, String> mapDel = new HashMap<String, String>();
  Map<String, String> mapChange = new HashMap<String, String>();
  Map<String, String> mapUnChange = new HashMap<String, String>();
  Iterator<String> it = mapA.keySet().iterator();
  while (it.hasNext()) {
   String key = it.next();
   String val = mapA.get(key);
   if (mapB.containsKey(key)) {
    String bVal = mapB.get(key);
    if (val != null && val.equals(bVal) || val == bVal) {
     mapUnChange.put(key, val);
    } else {
     mapChange.put(key, val);
    }
    mapAdd.remove(key);
   } else {
    mapDel.put(key, val);
   }
  }
 }




Related posts

coded by nessus
分享:  DeliciousGReader鲜果豆瓣CSDN网摘
Trackback

no comment untill now

Add your comment now

无觅相关文章插件