HashMap, TreeMap and LinkedHashMap difference
Difference HashMap and LinkedHashMap contains data in key value pair. TreeMap also contains data in key value pair but it is sorted according to natural ordering (ascending order). Map<Integer, String> codeCityHashMap = new HashMap<Integer, String>(); codeCityHashMap.put(11, "Delhi"); codeCityHashMap.put(22, "Mumbai"); codeCityHashMap.put(33, "Kolkata"); codeCityHashMap.put(44, "Chennai"); Map<Integer, String> codeCityLinkedHashMap = new LinkedHashMap<Integer, String>(); codeCityLinkedHashMap.put(11, "Delhi"); codeCityLinkedHashMap.put(22, "Mumbai"); codeCityLinkedHashMap.put(33, "Kolkata"); codeCityLinkedHashMap.put(44, "Chennai"); Map<Integer, String> codeCityTreeMap = new TreeMap<Integer, String>(); codeCityTreeMap.put(44, "Chennai"); codeCityTreeMap.put(11, "Delhi"); codeCityTreeMap.put(33, "Kolkata"); codeCityTreeMap.put(22, "Mumbai...
Comments
Post a Comment