Java LinkedHashMap
In Java, LinkedHashMap is a class that extends the HashMap class and provides a key-value based data structure that maintains the order of the keys. It is part of the java.util package and allows null values and null keys.
Here are some of the most commonly used methods in the LinkedHashMap class:
void clear(): This method removes all the key-value mappings from theLinkedHashMap.boolean containsKey(Object key): This method returnstrueif theLinkedHashMapcontains a mapping for the specified key, otherwisefalse.boolean containsValue(Object value): This method returnstrueif theLinkedHashMapcontains one or more mappings to the specified value, otherwisefalse.Set<Map.Entry<K, V>> entrySet(): This method returns aSetview of the key-value mappings in theLinkedHashMap.V get(Object key): This method returns the value to which the specified key is mapped, ornullif the key is not mapped to any value.boolean isEmpty(): This method returnstrueif theLinkedHashMapcontains no key-value mappings, otherwisefalse.Set<K> keySet(): This method returns aSetview of the keys in theLinkedHashMap.V put(K key, V value): This method associates the specified value with the specified key in theLinkedHashMap. If theLinkedHashMappreviously contained a mapping for the key, the old value is replaced with the new value and the old value is returned.void putAll(Map<? extends K, ? extends V> m): This method copies all of the mappings from the specifiedMapto thisLinkedHashMap.V remove(Object key): This method removes the mapping for the specified key from theLinkedHashMap, if it is present.int size(): This method returns the number of key-value mappings in theLinkedHashMap.Collection<V> values(): This method returns aCollectionview of the values in theLinkedHashMap.
In addition to the methods inherited from the HashMap class, the LinkedHashMap class also has two additional methods for manipulating the order of the keys:
boolean removeEldestEntry(Map.Entry<K, V> eldest): This method is called by theputmethod to determine whether to remove the eldest entry. By default, this method returnsfalse, indicating that the eldest entry should not be removed. Subclasses can override this method to provide custom eviction policies.boolean accessOrder(): This method returnstrueif theLinkedHashMapis in access-order mode, meaning that the order of the keys is based on their access order (i.e., the most recently accessed key is moved to the end of the list), rather than their insertion order. The default value isfalse.
