I tried to create a HashMap with the following details: -
HashMap<Integer,String> test = new HashMap<Integer,String>(); test.put(1, "Value1"); test.put(2, "Value2"); test.put(3, "Value3"); test.put(4, "Value4"); test.put(5, "Value5"); test.put(6, "Value6"); test.put(7, "Value7"); test.put(8, "Value8"); test.put(9, "Value9"); test.put(10, "Value10"); test.put(11, "Value11"); test.put(12, "Value12"); test.put(13, "Value13"); test.put(14, "Value14"); test.put(15, "Value15"); test.put(16, "Value16"); test.put(17, "Value17"); test.put(18, "Value18"); test.put(19, "Value19"); test.put(20, "Value20");
and I saw that each entrance was placed in a different bucket. This means that a different hash code was calculated for each key. Now, if I change my code as follows: -
HashMap<Integer,String> test = new HashMap<Integer,String>(16,2.0f); test.put(1, "Value1"); test.put(2, "Value2"); test.put(3, "Value3"); test.put(4, "Value4"); test.put(5, "Value5"); test.put(6, "Value6"); test.put(7, "Value7"); test.put(8, "Value8"); test.put(9, "Value9"); test.put(10, "Value10"); test.put(11, "Value11"); test.put(12, "Value12"); test.put(13, "Value13"); test.put(14, "Value14"); test.put(15, "Value15"); test.put(16, "Value16"); test.put(17, "Value17"); test.put(18, "Value18"); test.put(19, "Value19"); test.put(20, "Value20");
I found that some of the values that were placed in different buckets are now placed in a bucket that already contains some values, even if their hash value is different. Can someone help me understand the same thing?
thanks