HashMap isEmpty() Method in Java

The isEmpty() method of HashMap checks if the map contains any key/value pairs. It returns true if the map does not contain any entries. More formally, it returns true if the size of the HashMap is equal to zero. If the size of the HashMap is greater than zero then Read more…

HashMap size() Method in Java

The size() method of HashMap returns the number of key-value entries present in the map. When we create the HashMap its size is zero. This size of the HashMap increases as we add key-value pairs and reduce as we remove the entries. After clearing the HashMap the size again becomes Read more…

HashMap remove() Method in Java

The remove(K key) method of HashMap removes the entry for the specified key from the map. It returns the value associated with the key. To remove a specific key-value combination from the HashMap use the remove(K key, V value) method. The remove(key, value) method removes the entry only when both Read more…

HashMap entrySet() Method in Java

The entrySet() method of HashMap returns the set view of the entries in this map. Syntax Set<Entry<K, V>> entrySet() Parameters It does not take any parameters. Return Value It returns the set of entries Program Output Key-Value entries in map: [101=John, 102=Adam, 103=Ricky, 104=Chris]

HashSet clear() Method in Java

The clear() method of HashSet removes all the elements from the HashSet. The HashSet becomes empty after the call to the clear() method. Syntax Parameters It does not take any parameter and does not return anything. Return Value It does not return anything. Program 1 Output Set elements before clear: Read more…

HashSet isEmpty() Method in Java

The isEmpty() method of HashSet checks if the HashSet is empty or not. If the HashSet is empty then it returns true otherwise returns false. More formally, it returns true if the size of the HashSet is equal to zero. If the size is greater than zero then the isEmpty() Read more…

HashSet clone() Method in Java

The clone() method of HashSet returns a shallow copy of this HashSet instance. It overrides the clone() method of Object. Syntax Parameters It does not take any parameter Return Value it returns a shallow copy of this HashSet instance. Program 1 Output Set elements : [50, 20, 40, 10, 30] Read more…

HashSet remove() Method in Java

The remove(Element e) method of HashSet removes the specified element from the set. Syntax Parameters e is the element to be removed Return Value It returns true on successful removal of the element otherwise false if the element is not found in the HashSet. Program Output Set elements : [50, Read more…

HashSet size() Method in Java

The size() method of HashSet returns the number of elements available in the HashSet. Syntax Parameters It does not take any parameter Return Value It returns the number of elements in the HashSet Program 1 Output Set elements: [50, 20, 40, 10, 30] Number of elements in set: 5

HashSet contains() Method in Java

The contains(Element e) method of HashSet checks if the HashSet contains the specified element or not. It returns true if the HashSet contains the specified element otherwise it returns false. Syntax Parameters e is the element whose presence in this HashSet is to be checked. Return Value It returns true Read more…