The Wayback Machine - https://web.archive.org/web/20241119080012/https://www.geeksforgeeks.org/hashset-isempty-method-in-java/
Open In App

HashSet isEmpty() Method in Java

Last Updated : 26 Nov, 2018
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The Java.util.HashSet.isEmpty() method is used to check if a HashSet is empty or not. It returns True if the HashSet is empty otherwise it returns False.

Syntax:

Hash_Set.isEmpty()

Parameters: This method does not take any parameter

Return Value: The function returns True if the set is empty else returns False.

Below program illustrate the Java.util.HashSet.isEmpty() method:




// Java code to illustrate contains()
import java.io.*;
import java.util.HashSet;
  
public class HashSetDemo {
    public static void main(String args[])
    {
        // Creating an empty HashSet
        HashSet<String> set = new HashSet<String>();
  
        // Use add() method to add elements into the Set
        set.add("Welcome");
        set.add("To");
        set.add("Geeks");
        set.add("4");
        set.add("Geeks");
  
        // Displaying the HashSet
        System.out.println("HashSet: " + set);
  
        // Check for the empty set
        System.out.println("Is the set empty: " + set.isEmpty());
  
        // Clearing the set using clear() method
        set.clear();
  
        // Again Checking for the empty set
        System.out.println("Is the set empty: " + set.isEmpty());
    }
}


Output:

HashSet: [4, Geeks, Welcome, To]
Is the set empty: false
Is the set empty: true

Previous Article
Next Article

Similar Reads

Java String isEmpty() method with example
Java.lang.String.isEmpty() String method checks whether a String is empty or not. This method returns true if the given string is empty, else it returns false. The isEmpty() method of the String class is included in Java string since JDK 1.6. In other words, you can say that this method returns true if the length of the string is 0. Syntax of Java
3 min read
TreeSet isEmpty() Method in Java
The Java.util.TreeSet.isEmpty() method is used to check and verify if a TreeSet is empty or not. It returns True if the TreeSet is empty else it returns False. Syntax: Tree_Set.isEmpty() Parameters: The method does not take any parameter Return Value: The function returns True if the set is empty else it returns False. Below program illustrate the
1 min read
HashMap isEmpty() Method in Java
The java.util.HashMap.isEmpty() method of HashMap class is used to check for the emptiness of the map. The method returns True if no key-value pair or mapping is present in the map else False. Syntax: Hash_Map.isEmpty() Parameters: The method does not take any parameters. Return Value: The method returns boolean true if the map is empty or does not
2 min read
Hashtable isEmpty() Method in Java
The java.util.Hashtable.isEmpty() method of Hashtable class is used to check for the emptiness of the table. The method returns True if no key-value pair or mapping is present in the table else False. Syntax: Hash_Table.isEmpty() Parameters: The method does not take any parameters. Return Value: The method returns boolean true if the table is empty
2 min read
ArrayDeque isEmpty() Method in Java
The Java.util.ArrayDeque.isEmpty() method in Java is used to check and verify if an ArrayDeque is empty or not. It returns True if the Deque is empty else it returns False. Syntax: Array_Deque.isEmpty() Parameters: The method does not take any parameter. Return Value: The function returns True if the deque is empty else it returns False. Below prog
2 min read
BitSet isEmpty() method in Java
BitSet is a class defined in the java.util package. It creates an array of bits represented by boolean values. Prerequisite : Java BitSet | Set 1 Bitset.isEmpty() This method is used to check if there are any bits that are set to true, in the specified BitSet. This method returns true if this BitSet contains no bits that are set to true. Syntax: pu
2 min read
WeakHashMap isEmpty() Method in Java with Examples
The java.util.WeakHashMap.isEmpty() method of HashMap class is used to check for the emptiness of the map. The method returns True if no key-value pair or mapping is present in the map else False. Syntax: Weak_Hash_Map.isEmpty() Parameters: The method does not take any parameters. Return Value: The method returns boolean true if the map is empty or
2 min read
Vector isEmpty() Method in Java
The Java.util.Vector.isEmpty() method in Java is used to check and verify if a Vector is empty or not. It returns True if the Vector is empty else it returns False. Syntax: Vector.isEmpty() Parameters: This method does not take any parameter. Return Value: This function returns True if the Vectoris empty else it returns False. Below programs illust
2 min read
LinkedTransferQueue isEmpty() method in Java
The isEmpty() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which checks if this queue is empty or not. Syntax: LinkedTransferQueue.isEmpty() Return Value: The function returns a boolean value. It returns true if the LinkedTransferQueue is empty and returns false otherwise. Below programs illustrate the LinkedTr
1 min read
ConcurrentHashMap isEmpty() Method in Java
The isEmpty() method in Java's ConcurrentHashMap class is used to check whether the map is empty or not. It has the following signature: boolean isEmpty() The isEmpty() method works in a concurrent environment, which means that it can be called from multiple threads without causing any data race or synchronization issues. When an isEmpty() operatio
2 min read
ConcurrentSkipListSet isEmpty() method in Java
The java.util.concurrent.ConcurrentSkipListSet.isEmpty() method is an in-built function in Java which is used to check if this set is empty or not. Syntax: ConcurrentSkipListSet.isEmpty() Parameters: The function does not accepts any parameter. Return Value: The function returns a boolean value. It returns true if the ConcurrentSkipListSet is empty
2 min read
ConcurrentLinkedQueue isEmpty() method in Java
The isEmpty() method of ConcurrentLinkedQueue is used to check if this queue is empty or not. It returns true if ConcurrentLinkedQueue contains zero number of elements means if the ConcurrentLinkedQueue is empty. Syntax: public boolean isEmpty() Returns: This method returns true if this ConcurrentLinkedQueue contains zero number of elements. Below
2 min read
CopyOnWriteArrayList isEmpty() method in Java
The isEmpty(E e) method of CopyOnWriteArrayList checks if the list is empty or not. It returns true if the list is empty, else it returns false. Syntax: public boolean isEmpty() Parameters: The function does not accepts any parameter. Return Value: The function returns true if the list is empty, otherwise it returns false. Below programs illustrate
2 min read
CopyOnWriteArraySet isEmpty() method in Java
The isEmpty(E e) method of CopyOnWriteArraySet checks if the Set is empty or not. It returns true if the Set is empty, else it returns false. Syntax: public boolean isEmpty() Return Value: The function returns true if the Set is empty, otherwise it returns false. Below programs illustrate the above function: Program 1: Java Code // Java Program to
1 min read
AbstractCollection isEmpty() Method in Java with Examples
The isEmpty() method of Java AbstractCollection is used to check and verify if a Collection is empty or not. It returns True if the Collection is empty else it returns False. Syntax: AbstractCollection.isEmpty() Parameters: The method does not take any parameter. Return Value: The function returns True if the collection is empty else it returns Fal
2 min read
AbstractMap isEmpty() Method in Java with Examples
The AbstractMap.isEmpty() method of AbstractMap class is used to check for the emptiness of the map. The method returns True if no key-value pair or mapping is present in the map else False. Syntax: AbstractMap.isEmpty() Parameters: The method does not take any parameters. Return Value: The method returns boolean true if the map is empty or does no
2 min read
ConcurrentLinkedDeque isEmpty() method in Java with Examples
The java.util.concurrent.ConcurrentLinkedDeque.isEmpty() is an in-built function in Java which checks whether the deque contains elements or not. Syntax: public boolean isEmpty() Parameters: The function does not accepts any parameter. Return: This method returns a boolean value stating whether this deque is empty or not. Below programs illustrate
1 min read
AbstractSequentialList isEmpty() method in Java with Example
The isEmpty() method of AbstractSequentialList in Java is used to check whether this AbstractSequentialList is empty or not. It returns an boolean value stating the same. Syntax: public boolean isEmpty() Parameters: This function has no parameters. Returns: The method returns an boolean value which states that this instance of the AbstractSequentia
2 min read
Stack isEmpty() method in Java with Example
The Java.util.Stack.isEmpty() method in Java is used to check and verify if a Stack is empty or not. It returns True if the Stack is empty else it returns False. Syntax: Stack.isEmpty() Parameters: This method does not take any parameter. Return Value: This function returns True if the Stackis empty else it returns False. Below programs illustrate
2 min read
LinkedBlockingDeque isEmpty() method in Java with Example
The isEmpty() method of LinkedBlockingDeque in Java is used to check whether this LinkedBlockingDeque is empty or not. It returns an boolean value stating the same. Syntax: public boolean isEmpty() Parameters: This method does not accepts parameter. Returns: The method returns an boolean value which states that this instance of the LinkedBlockingDe
2 min read
AbstractSet isEmpty() method in Java with Example
The isEmpty() method of AbstractSet in Java is used to check whether this AbstractSet is empty or not. It returns an boolean value stating the same. Syntax: public boolean isEmpty() Parameters: This function has no parameters. Returns: The method returns an boolean value which states that this instance of the AbstractSet is empty or not. Below exam
2 min read
Set isEmpty() method in Java with Examples
The java.util.Set.isEmpty() method is used to check if a Set is empty or not. It returns True if the Set is empty otherwise it returns False. Syntax: boolean isEmpty() Parameters: This method does not take any parameter Return Value: The method returns True if the set is empty else returns False. Below program illustrate the java.util.Set.isEmpty()
1 min read
Map isEmpty() Method in Java with Examples
This method is used to check if a map is having any entry for key and value pairs. If no mapping exists, then this returns true. Syntax: boolean isEmpty() Parameters: This method has no argument. Returns: This method returns True if the map does not contain any key-value mapping. Below programs show the implementation of int isEmpty() method. Progr
1 min read
ConcurrentSkipListMap isEmpty() method in Java with Examples
The isEmpty() method of java.util.concurrent.ConcurrentSkipListMap is an in-built function in Java which returns boolean value that is it returns true if this map contains no key-value mappings otherwise false. Syntax: public boolean isEmpty() Parameter: The function does not accepts any parameters. Return Value: The function returns true if this m
1 min read
Properties isEmpty() method in Java with Examples
The isEmpty() method of Properties class is used to check if this Properties object is empty or not. Syntax: public boolean isEmpty() Parameters: This method accepts no parameters Returns: This method returns a boolean value stating if this Properties object is empty or not. Below programs show the implementation of int isEmpty() method. Program 1:
2 min read
SortedSet isEmpty() method in Java with Examples
The java.util.SortedSet.isEmpty() method is used to check if a SortedSet is empty or not. It returns True if the SortedSet is empty otherwise it returns False. Syntax: boolean isEmpty() Parameters: This method does not take any parameter. Return Value: The method returns True if the SortedSet is empty else returns False. Note: The isEmpty() method
1 min read
SortedMap isEmpty() method in Java with Examples
The isEmpty() method of SortedMap interface in Java is used to check if a map is having any entry for key and value pairs. If no mapping exists, then this returns true. Syntax: boolean isEmpty() Parameters: This method has no argument. Returns: This method returns True if the map does not contain any key-value mapping. Note: The isEmpty() method in
2 min read
LinkedHashSet isEmpty() method in Java
The Java.util.LinkedHashSet.isEmpty() method is used to check if a LinkedHashSet is empty or not. It returns True if the LinkedHashSet is empty otherwise it returns False. Syntax: Linked_Hash_Set.isEmpty() Parameters: This method does not take any parameter Return Value: The function returns True if the set is empty else returns False. Below progra
1 min read
NavigableSet isEmpty() method in Java
The java.util.NavigableSet.isEmpty() method is used to check if a NavigableSet is empty or not. It returns True if the NavigableSet is empty otherwise it returns False. Syntax: boolean isEmpty() Parameters: This method does not take any parameter Return Value: The method returns True if the NavigableSet is empty else returns False. Below program il
1 min read
CompositeName isEmpty() method in Java with Examples
The isEmpty() method of a javax.naming.CompositeName class is used to check this composite name object is empty or not. A composite name is said to be empty if it has zero components. Syntax: public boolean isEmpty() Parameters: This method accepts nothing. Return value: This method returns true if this composite name is empty, false otherwise. Bel
1 min read
three90RightbarBannerImg