Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

CopyOnWriteArraySet isEmpty() method in Java

  • Last Updated : 25 Nov, 2020

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:  

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

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




// Java Program to illustrate the
// isEmpty() method in CopyOnWriteArraySet
 
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");
    }
}
Output: 
CopyOnWriteArraySet: [32, 67, 98, 100]

Set is not empty

 

Program 2:  

Java




// Java Program to illustrate the
// isEmpty() method in CopyOnWriteArraySet
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");
    }
}
Output: 
CopyOnWriteArraySet: []

Set is empty

 

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!