· Hash table and linked list implementation of the Map interface
· LinkedHashMap differs from HashMap in that the order is maintained
· Performance is below that of HashMap, due to the expense of maintaining the linked list
· Its methods are not synchronized
Example
package com.vinod.collections;
import java.util.LinkedHashMap;
import java.util.Map;
public class LinkedHashMapExample {
public static void main(String[] args) {
Map<Object, String> lHashm = new LinkedHashMap<Object, String>();
lHashm.put(1, "Bangalore");
lHashm.put(2, "Chennai");
lHashm.put(3, "Cochin");
lHashm.put(4, "Hydrabad");
System.out.println("The Elements are : " + lHashm);
for (Map.Entry<Object, String> entry : lHashm.entrySet()) {
System.out.println(entry.getKey() + " :" + entry.getValue());
}
}
}
import java.util.LinkedHashMap;
import java.util.Map;
public class LinkedHashMapExample {
public static void main(String[] args) {
Map<Object, String> lHashm = new LinkedHashMap<Object, String>();
lHashm.put(1, "Bangalore");
lHashm.put(2, "Chennai");
lHashm.put(3, "Cochin");
lHashm.put(4, "Hydrabad");
System.out.println("The Elements are : " + lHashm);
for (Map.Entry<Object, String> entry : lHashm.entrySet()) {
System.out.println(entry.getKey() + " :" + entry.getValue());
}
}
}
Output
The Elements are : {1=Bangalore, 2=Chennai, 3=Cochin, 4=Hydrabad}
1 :Bangalore
2 :Chennai
3 :Cochin
4 :Hydrabad
No comments:
Post a Comment