Java LinkedHashMap class
suggest changeKey Points:-
- Hash table and linked list implementation of the Map interface, with predictable iteration order.
- It extends
HashMapand implements theMapinterface. - It contains values based on the key.
- Keys are unique. Values do not have to be unique.
- It may have one null key and multiple null values.
- The no-argument constructor iterates in insertion order.
LinkedHashMap(int, float, boolean)can iterate in access order instead.
Methods :-
- void clear().
- boolean containsKey(Object key).
- Object get(Object key).
- protected boolean removeEldestEntry(Map.Entry eldest)
Example :-
public static void main(String arg[])
{
LinkedHashMap<String, String> lhm = new LinkedHashMap<String, String>();
lhm.put("Ramesh", "Intermediate");
lhm.put("Shiva", "B-Tech");
lhm.put("Santosh", "B-Com");
lhm.put("Asha", "Msc");
lhm.put("Raghu", "M-Tech");
Set set = lhm.entrySet();
Iterator i = set.iterator();
while (i.hasNext()) {
Map.Entry me = (Map.Entry) i.next();
System.out.println(me.getKey() + " : " + me.getValue());
}
System.out.println("The Key Contains : " + lhm.containsKey("Shiva"));
System.out.println("The value corresponding to the key : " + lhm.get("Asha"));
}
Set, Iterator, and Map.Entry in the loop are raw, so each element is cast. The iteration order of this map is the order of the put calls.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents