Java LinkedHashMap class

  • This class extends HashMap and maintains a linked list of the entries in the map, in the order in which they were inserted.
  • It contains only unique elements
  • It may have one null key and multiple null values.
  • It is same as HashMap instead maintains insertion order.

LinkedHashMap class:

second

Example

import java.util.*;

      class DemoLHM{

	public static void main(String args[]){



	LinkedHashMap lhm=new LinkedHashMap();



	lhm.put(100,"A");

	lhm.put(101,"B");

    lhm.put(102,"C");



	for(Map.Entry m:lhm.entrySet()){

	System.out.println(m.getKey()+" "+m.getValue());

	}

	}

	}				

Output


100 A

101 B

102 C