9

sに関する調査を行っていMapたところ、同じキーを意図的に 2 回追加すると、Map のサイズは同じままになることがわかりました。この背後にある技術的な理由は何ですか?

 Map map=new HashMap();//HashMap key random order.
         map.put("Amit","Java");
         map.put("Amit","Java");

取得するコード...

System.out.println("There are "+map.size()+" elements in the map.");
         System.out.println("Content of Map are...");
         Set s=map.entrySet();
         Iterator itr=s.iterator();
         while(itr.hasNext())
         {
             Map.Entry m=(Map.Entry)itr.next();
             System.out.println(m.getKey()+"\t"+m.getValue()+"\t"+ m.hashCode());
          }

私が得る結果:

There are 1 elements in the map.
Content of Map are...
Amit    Java    3943477
4

3 に答える 3