- LinkedHashMap cast is i of the cast of map interface which extends HashMap cast as well as implements Map interface.
- It is combination of linked listing and Hash table implementation of the Map interface as well as that's why it is called LinkedHashMap.
- It is maintaining doubly-linked listing insertion companionship inwards which keys were inserted into the map.
- It allows to shop nix elements as well as optional Map operations are likewise available.
- It is non synchronized implementation therefore if whatever thread modifies map structurally when map is accessed past times multiple threads as well as therefore it must live on synchronized externally.
- void clear() : It volition take away all mappings from map.
- boolean containsValue(Object value) : It volition banking concern stand upward for for value inwards map as well as supply truthful if values be inwards map.
- V get(Object key) : It volition supply value which is mapped amongst specified fundamental inwards map. Else it volition supply null.
- protected boolean removeEldestEntry(Map.Entry<K,V> eldest) : It will returns truthful if this map should take away its eldest entry.
package JAVAExamples; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Set; populace cast ExampleLinkedHashMap { populace static void main(String[] args) { // Create a hash map. LinkedHashMap<String, Double> fifty = novel LinkedHashMap<String, Double>(); // Put elements to the map. l.put("Bicycle", novel Double(134.33)); l.put("Car", novel Double(353.12)); l.put("Bus", novel Double(-598.23)); l.put("Train", novel Double(193.56)); l.put("Motorcycle", novel Double(39.48)); // Print LinkedHashMap. System.out.println("LinkedHashMap elements are : " + l); // Get size of LinkedHashMap. System.out.println("Size of LinkedHashMap is : " + l.size()); // Get value of key. System.out.println("Value of Bus is " + l.get("Bus")); // Check if LinkedHashMap is empty. System.out.println("LinkedHashMap is empty? : " + l.isEmpty()); // Check of LinkedHashMap has given value or not System.out.println("LinkedHashMap has 353.12 value? : "+ l.containsValue(353.12)); // Check of LinkedHashMap has given fundamental or not System.out.println("LinkedHashMap has taxi key? : "+ l.containsKey("taxi")); // Iterate over LinkedHashMap. Set<Entry<String, Double>> second = l.entrySet(); // Get an iterator Iterator<Entry<String, Double>> i = s.iterator(); // Display elements acre (i.hasNext()) { Map.Entry one thousand = (Map.Entry) i.next(); System.out.print(m.getKey() + ": "); System.out.println(m.getValue()); } System.out.println(); } }
Output :
LinkedHashMap elements are : {Bicycle=134.33, Car=353.12, Bus=-598.23, Train=193.56, Motorcycle=39.48} Size of LinkedHashMap is : five Value of Bus is -598.23 LinkedHashMap is empty? : imitation LinkedHashMap has 353.12 value? : truthful LinkedHashMap has taxi key? : imitation Bicycle: 134.33 Car: 353.12 Bus: -598.23 Train: 193.56 Motorcycle: 39.48
<< PREVIOUS || NEXT >>