java tutorial - Java LinkedHashMap class - java programming - learn java - java basics - java for beginners
Java LinkedHashMap class is Hash table and Linked list implementation of the Map interface, with predictable iteration order. It inherits HashMap class and implements the Map interface.
The important points about Java LinkedHashMap class are:
- A LinkedHashMap contains values based on the key.
- It contains only unique elements.
- It may have one null key and multiple null values.
- It is same as HashMap instead maintains insertion order.
LinkedHashMap class declaration
Let's see the declaration for java.util.LinkedHashMap class.
LinkedHashMap class Parameters
Let's see the Parameters for java.util.LinkedHashMap class.
- K: It is the type of keys maintained by this map.
- V: It is the type of mapped values.
Learn java - java tutorial - linked-hashmap - java examples - java programs
Constructors of Java 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 fillRatio) | It is used to initialize both the capacity and the fillRatio. |
LinkedHashMap(Map m) | It is used to initialize the LinkedHashMap with the elements from the given Map class m. |
Methods of Java LinkedHashMap class
Method | Description |
---|---|
Object get(Object key) | It is used to return the value to which this map maps the specified key. |
void clear() | It is used to remove all mappings from this map. |
boolean containsKey(Object key) | It is used to return true if this map maps one or more keys to the specified value. |