It maintain the order of elements according to the order in which keys weer inserted into map.
Inserted Order is not affected if a key is re-inserted int the map.
Key Duplication is not allowed
package collection.demos;
import java.util.LinkedHashMap;
public class LinkedHashMapDemo {
public static void main(String[] args) {
LinkedHashMap<String,String> abbreviations=new LinkedHashMap<String,String>();
abbreviations.put("DB", "Data Base");
abbreviations.put("Sys", "System");
abbreviations.put("SRS", "Software Requirements Specification");
System.out.println("Elements : "+abbreviations);
abbreviations.put("Sys","Systems");//same output will be
System.out.println("Elements : "+abbreviations);
System.out.println("Elements of key Sys : "+abbreviations.get("Sys"));
}
}
Inserted Order is not affected if a key is re-inserted int the map.
Key Duplication is not allowed
package collection.demos;
import java.util.LinkedHashMap;
public class LinkedHashMapDemo {
public static void main(String[] args) {
LinkedHashMap<String,String> abbreviations=new LinkedHashMap<String,String>();
abbreviations.put("DB", "Data Base");
abbreviations.put("Sys", "System");
abbreviations.put("SRS", "Software Requirements Specification");
System.out.println("Elements : "+abbreviations);
abbreviations.put("Sys","Systems");//same output will be
System.out.println("Elements : "+abbreviations);
System.out.println("Elements of key Sys : "+abbreviations.get("Sys"));
}
}
Comments