List isEmpty() method in Java with Examples

The isEmpty() method of List interface in java is used to check if a list is empty or not. It returns true if the list contains no elements otherwise it returns false if the list contains any element.


boolean isEmpty()

Parameter: It does not accepts any parameter.

Returns: It returns True if the list has no elements else it returns false. The return type is of datatype boolean.

Error and Exceptions: This method has no error or exceptions.

Program to demonstrate working of isEmpty() in Java:





// Java code to demonstrate the working of
// isEmpty() method in List interface
import java.util.*;
public class GFG {
    public static void main(String[] args)
        // creating an Empty Integer List
        List<Integer> arr = new ArrayList<Integer>(10);
        // check if the list is empty or not
        // using isEmpty() function
        boolean ans = arr.isEmpty();
        if (ans == true)
            System.out.println("The List is empty");
            System.out.println("The List is not empty");
        // addition of a element to
        // the List
        // check if the list is empty or not
        // after adding an element
        ans = arr.isEmpty();
        if (ans == true)
            System.out.println("The List is empty");
            System.out.println("The List is not empty");



The List is empty
The List is not empty


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

My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to 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.

Improved By : Akanksha_Rai