LinkedList removeLast() method with example in java

The removeLast() method of LinkedList retrieves and removes the last element in this list. It throws a NoSuchElementException if this list is empty. Syntax Parameters It doesn’t take any parameter Return Value the removed element in this list Exception It throws NoSuchElementException exception if this list is empty. Program 1 Read more…

HashMap replace() Method in Java

The replace(K key, V value) method of HashMap replaces an entry for the specified key. It returns replaced value. It returns null if the map does not contain an entry for the specified key. We can also use the replace(K key, V oldValue, V newValue) method to replace the old Read more…

HashMap containsValue() Method in Java

The containsValue(V value) method of HashMap checks if the map contains the specified value or not. It returns true if the map contains the specified value otherwise it returns false. Some implementations of map throw NullPointerException if the value is null. As HashMap supports null values. So, we can use Read more…

HashMap containsKey() Method in Java

The containsKey(K key) method of HashMap checks if the map contains a specified key or not. It returns true if the map contains the specified key otherwise returns false. Some implementations of map throw NullPointerException if the key is null. As HashMap supports null key. So, we can use this Read more…

HashMap values() Method in Java

The values() method of HashMap returns a collection of the values in this map. Returned collection is backed by the map. This means if the map changes then the returned collection changes. Similarly, if the retuned collection changed then the map changes. Syntax Parameters It does not take any parameter Read more…

HashMap get() Method in Java

The get(K key) method of HashMap returns the value for the specified key. If the map does not contain an entry for the specified key then it returns null. It throws NullPointerException if the specified key is null and this map does not permit null keys. Syntax Parameter The key Read more…

HashMap putAll() Method in Java

The putAll() method of HashMap copies all the entries of the specified map into this map. It throws NullPointerException if the specified map is null, or if this map does not permit null keys or values, and the specified map contains null keys or values. Syntax Parameters The map we Read more…

HashMap put() Method in Java

The put(key, value) method of HashMap inserts the key-value pair into the map. If the specified key is already available then it replaces the old value with the new value for that key. put method returns the previous value associated with the specified key if there was mapping for the Read more…