w3resource

Java ArrayList.isEmpty() Method

public boolean isEmpty()

The isEmpty() method is used to check if the list is empty or not.

Package: java.util

Java Platform: Java SE 8

Syntax:

isEmpty()

Return Value:
Returns true if a ArrayList object contains no elements; false otherwise.

Return Value Type: boolean

Pictorial presentation of ArrayList.isEmpty() Method

Java ArrayList.isEmpty() Method

Example: ArrayList.isEmpty Method

The following example shows how to determine if an ArrayList is empty.

import java.util.*;

public class test {
    public static void main(String[] args)
    {
      // Create an empty ArrayList.
        ArrayList myArrayList = new ArrayList();
		
	 // Test whether the array is empty or not.
        if (myArrayList.isEmpty())
        {
            System.out.println("The ArrayList is empty");
        }
        else
        {
            System.out.println("The ArrayList is not empty");
        }
    }
}

Output:

F:\java>javac test.java
F:\java>java test
  The ArrayList is empty

Java Code Editor:

Previous:size Method
Next:contains Method



Follow us on Facebook and Twitter for latest update.