how to compare two hash maps?

后端 未结 7 1042
独厮守ぢ
独厮守ぢ 2021-02-08 02:22

How to compare the values in both hash maps with the help of keys ? Since the keys are identical whereas values are\'nt. and return boolean result for each key comparision. like

7条回答
  •  离开以前
    2021-02-08 02:53

    Map map = new HashMap();
    map.put("AA","aaa");
    map.put("BB","bbb");
    map.put("CC","ccc");
    map.put("DD","ffffd");
    
    Map map2 = new HashMap();
    map2.put("BB","bbb");
    map2.put("AA","aaa");
    map2.put("DD","ffffd");
    map2.put("CC","ccc");
    
    if(map.equals(map2))
    {
        System.out.println("Eql");
    }
    else
    {
        System.out.println("Not");
    }
    

提交回复
热议问题