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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Java Program to illustrate the
// isEmpty() method in Java
  
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create object of CopyOnWriteArraySet
        CopyOnWriteArraySet<Integer> ArrSet
            = new CopyOnWriteArraySet<Integer>();
  
        // Add elements
        ArrSet.add(32);
        ArrSet.add(67);
        ArrSet.add(98);
        ArrSet.add(100);
  
        // print CopyOnWriteArraySet
        System.out.println("CopyOnWriteArraySet: " + ArrSet);
  
        // check using function
        if (ArrSet.isEmpty())
            System.out.println("\nSet is empty");
        else
            System.out.println("\nSet is not empty");
    }
}

chevron_right


Output:

CopyOnWriteArraySet: [32, 67, 98, 100]

Set is not empty

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java Program to illustrate the
// isEmpty() method in Java
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create object of CopyOnWriteArraySet
        CopyOnWriteArraySet<String> ArrSet
            = new CopyOnWriteArraySet<String>();
  
        // print CopyOnWriteArraySet
        System.out.println("CopyOnWriteArraySet: "
                           + ArrSet);
  
        // check using function
        if (ArrSet.isEmpty())
            System.out.println("\nSet is empty");
        else
            System.out.println("\nSet is not empty");
    }
}

chevron_right


Output:

CopyOnWriteArraySet: []

Set is empty

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CopyOnWriteArraySet.html#isEmpty–

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.