InterviewSolution
| 1. |
What Happens If Hashmap Has Duplicate Keys? |
|
Answer» If an attempt is made to add the same key twice, it won't CAUSE any error but the VALUE which is added later will override the PREVIOUS value. As Exp. If you have a Map, cityMap and you add TWO values with same key in the cityMap, Kolkata will override the New Delhi. cityMap.put("5", "New Delhi"); If an attempt is made to add the same key twice, it won't cause any error but the value which is added later will override the previous value. As Exp. If you have a Map, cityMap and you add two values with same key in the cityMap, Kolkata will override the New Delhi. cityMap.put("5", "New Delhi"); |
|