LinkedHashMap class Example

import java.util.*;
class LinkedHashMapDemo
{ public static void main(String args[])
  { // Create a hash map.
LinkedHashMap hm = new LinkedHashMap();
      // Put elements to the map
hm.put("Devesh",1000.00);
hm.put("Rahul",1500.00);
hm.put("Rakesh",1200.00);
hm.put("Manohar",900.00);
hm.put("Prateek",1300.00);
// Get a set of the entries.
Set set = hm.entrySet();
// Display the set.
Iterator i = set.iterator();
while(i.hasNext())
{ Map.Entry me = (Map.Entry) i.next();
System.out.print(me.getKey() + ": ");
      System.out.println(me.getValue());
}
  System.out.println();
  // Deposit 1000 into John Doe's account.
double balance = (Double) hm.get("Prateek");
hm.put("Prateek", balance + 1000);
balance = (Double)hm.get("Prateek");
System.out.println("Prateek's new balance: " + balance);
}
}

Comments