Java LinkedHashMap Methods
All LinkedHashMap Methods
A LinkedHashMap stores key/value pairs, like a HashMap. The difference is that a LinkedHashMap keeps the entries in the order in which they were added (insertion order). When you print it or loop through it, you get the entries in that order.
LinkedHashMap has the same methods as HashMap, and they work the same way, so the links in the table go to the HashMap reference pages. The type of the values is called V in the table.
| Method | Description | Return Type |
|---|---|---|
| clear() | Removes all entries from the map | void |
| clone() | Creates a copy of the map | Object |
| compute() | Computes a new value for a key, from the key and its current value | V |
| computeIfAbsent() | Computes a value for a key, only if the key is not in the map yet | V |
| computeIfPresent() | Computes a new value for a key, only if the key is already in the map | V |
| containsKey() | Checks if the map has an entry with the specified key | boolean |
| containsValue() | Checks if the map has an entry with the specified value | boolean |
| entrySet() | Returns a set of all entries (key/value pairs) in the map | Set |
| forEach() | Performs an action on every entry in the map | void |
| get() | Returns the value of the entry with the specified key | V |
| getOrDefault() | Returns the value of the entry with the specified key, or a default value if the key is not found | V |
| isEmpty() | Checks if the map is empty | boolean |
| keySet() | Returns a set of all keys in the map | Set |
| merge() | Combines a new value with the current value of a key, or adds the entry if the key is not found | V |
| put() | Adds an entry to the map, or replaces the value if the key is already there | V |
| putAll() | Adds all entries from another map to this map | void |
| putIfAbsent() | Adds an entry to the map, only if the key is not in the map yet | V |
| remove() | Removes an entry from the map | V|boolean |
| replace() | Replaces the value of an entry, only if the key is in the map | V|boolean |
| replaceAll() | Replaces the value of every entry with the result of a function | void |
| size() | Returns the number of entries in the map | int |
| values() | Returns a collection of all values in the map | Collection |