
Java LinkedHashMap class is Hashtable and Linked list implementation of the Map interface, with predictable iteration order. It inherits HashMap class and implements the Map interface.
Let's see the declaration for java.util.LinkedHashMap class.
Let's see the Parameters for java.util.LinkedHashMap class.
| Constructor | Description |
|---|---|
| LinkedHashMap() | It is used to construct a default LinkedHashMap. |
| LinkedHashMap(int capacity) | It is used to initialize a LinkedHashMap with the given capacity. |
| LinkedHashMap(int capacity, float loadFactor) | It is used to initialize both the capacity and the load factor. |
| LinkedHashMap(int capacity, float loadFactor, boolean accessOrder) | It is used to initialize both the capacity and the load factor with specified ordering mode. |
| LinkedHashMap(Map<? extends K,? extends V> m) | It is used to initialize the LinkedHashMap with the elements from the given Map class m. |
| Method | Description |
|---|---|
| V get(Object key) | It returns the value to which the specified key is mapped. |
| void clear() | It removes all the key-value pairs from a map. |
| boolean containsValue(Object value) | It returns true if the map maps one or more keys to the specified value. |
| Set<Map.Entry<K,V>> entrySet() | It returns a Set view of the mappings contained in the map. |
| void forEach(BiConsumer<? super K,? super V> action) | It performs the given action for each entry in the map until all entries have been processed or the action throws an exception. |
| V getOrDefault(Object key, V defaultValue) | It returns the value to which the specified key is mapped or defaultValue if this map contains no mapping for the key. |
| Set<K> keySet() | It returns a Set view of the keys contained in the map |
| protected boolean removeEldestEntry(Map.Entry<K,V> eldest) | It returns true on removing its eldest entry. |
| void replaceAll(BiFunction<? super K,? super V,? extends V> function) | It replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception. |
| Collection<V> values() | It returns a Collection view of the values contained in this map. |
Output:
100 Amit
101 Vijay
102 Rahul
Output:
Keys: [100, 101, 102] Values: [Amit, Vijay, Rahul] Key-Value pairs: [100=Amit, 101=Vijay, 102=Rahul]
Output:
Before invoking remove() method: {101=Amit, 102=Vijay, 103=Rahul}
After invoking remove() method: {101=Amit, 103=Rahul}
Output:
2 Details: 102 Data Communications & Networking Forouzan Mc Graw Hill 4 1 Details: 101 Let us C Yashwant Kanetkar BPB 8 3 Details: 103 Operating System Galvin Wiley 6
We request you to subscribe our newsletter for upcoming updates.