Java LinkedHashMap tutorial and example

Hash table and linked list implementation of the Map interface, with predictable iteration order. This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order). Note that insertion order is not affected if a key is re-inserted into the map.


package com.candidjava.core;
import java.util.LinkedHashMap;

public class LinkedHashMapExample {

	public static void main(String[] args) {
		LinkedHashMap<String,String> hm=new LinkedHashMap<String,String>();
		hm.put("password", "123456");
		hm.put("street", "shanthi nagar");
		hm.put("password", "789");
		hm.put(null, "chennai");
		hm.put(null, "Delhi");
		hm.put("altemail", null);
		hm.put("altph", null);
		System.out.println("LinkedHashMap ..  "+hm);
		System.out.println("size ... "+hm.size());		
LinkedHashMap ..  {name=candid,, password=789, street=shanthi nagar, null=Delhi, altemail=null, altph=null}
size ... 7

Click here for more LinkedHashMap example

Related Post