examples of Linked Hash Map in java programming

0

 Linked Hash Map:

  • Maintains insertion order.
  • Slower than Hash map.
  • I can expect a faster iteration.

Example:

public class Fruit{
public static void main(String[ ] args){
LinkedHashMap<Sting,String> names =new LinkedHashMap<String,String>( );
 names.put(“key1”,“cherry”);
 names.put(“key2”,“apple”);
 names.put(“key3”,“banana”);
 names.put(“key4”,“kiwi”);
 names.put(“key2”,“orange”);
 System.out.println(names);
 }
 }

Output:

{key2=apple, key1=cherry,key4=kiwi, key3=banana}

Duplicate keys are not allowed.

All Contributions

total contributions (0)

New to examplegeek.com?

Join us