Skip to content
Related Articles

Related Articles

CopyOnWriteArraySet isEmpty() method in Java

Improve Article
Save Article
  • Last Updated : 25 Nov, 2020
Improve Article
Save Article

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




// 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
Related Articles

Start Your Coding Journey Now!