GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection
  • Introduction3 min read
  • Variables2 min read
  • Data Types7 min read
  • Operators7 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — ArrayList isEmpty() Method in Java with Examples - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • Java Tutorial
  • Advanced Java
  • Interview Questions
  • Exercises
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • DSA in Java
  • Java Collection

ArrayList isEmpty() Method in Java with Examples

Last Updated : 22 Jul, 2026

The isEmpty() method of the ArrayList class is used to check whether an ArrayList contains any elements. It returns true if the list has no elements; otherwise, it returns false.

  • Checks whether an ArrayList is empty.
  • Returns a boolean value without modifying the list.
Java
import java.util.ArrayList;

public class GFG {
    public static void main(String[] args) {
      
        // Creating an empty ArrayList of Integers
        ArrayList<Integer> n = new ArrayList<>();

        // Checking if the ArrayList is empty
        boolean res = n.isEmpty();

        System.out.println("" + res);

        // Adding an element 
        // to the ArrayList
        n.add(21);

        // Checking again if the 
        // ArrayList is empty
        res = n.isEmpty();
        System.out.println("" + res);
    }
}

Output
true
false

Explanation: Initially, the ArrayList contains no elements, so isEmpty() returns true. After adding an element, the list is no longer empty, so it returns false.

Syntax

public boolean isEmpty()

Return Type: It returns a boolean value, true if the list is empty, otherwise false.

Example: Using isEmpty() with an ArrayList of Strings

Java
import java.util.ArrayList;

public class GFG {
    public static void main(String[] args) {

        // Create an ArrayList of Strings
        ArrayList<String> fruits = new ArrayList<>();

        System.out.println("Is list empty? " + fruits.isEmpty());

        fruits.add("Mango");
        fruits.add("Apple");

        System.out.println("Is list empty? " + fruits.isEmpty());
    }
}

Output
Is list empty? true
Is list empty? false

Explanation: The isEmpty() method checks whether the ArrayList contains any elements. After adding two strings, the method returns false.

Example: Using isEmpty() with Custom Objects

Java
import java.util.ArrayList;

class Student {
    String name;

    Student(String name) {
        this.name = name;
    }
}

public class GFG {
    public static void main(String[] args) {

        // Create an ArrayList of Student objects
        ArrayList<Student> students = new ArrayList<>();

        System.out.println(students.isEmpty());

        students.add(new Student("Alice"));

        System.out.println(students.isEmpty());
    }
}

Output
true
false

Explanation: The isEmpty() method works with any type of ArrayList, including custom objects. It returns true when the list has no objects and false after an object is added.

Difference Between isEmpty() and size()

isEmpty()size()
Returns true if the list is empty.Returns the number of elements in the list.
Return type is boolean.Return type is int.
Used to check whether a list has elements.Used to determine the exact number of elements.
More readable when checking if a list is empty.Useful when the element count is required.

Advantages of isEmpty() Method

  • Provides a simple way to check whether an ArrayList contains elements.
  • Improves code readability compared to checking size() == 0.
  • Does not modify the contents of the list.
  • Works with ArrayList of primitive wrapper classes, strings, and custom objects.
  • Useful for validation before performing list operations.
Comment

Explore

    Basics
    • Introduction3 min read
    • Variables2 min read
    • Data Types7 min read
    • Operators7 min read
    • Decision Making5 min read
    • Methods7 min read
    • Arrays7 min read
    • Strings5 min read
    OOP & Interface
    • Introduction6 min read
    • Constructors6 min read
    • Encapsulation3 min read
    • Inheritance8 min read
    • Polymorphism5 min read
    • Abstraction5 min read
    • Interfaces8 min read
    Collections
    • Collection class9 min read
    • Collection Interface5 min read
    • List Interface8 min read
    • Set Interface5 min read
    • Queue Interface5 min read
    • Map Interface in Java6 min read
    • Iterator4 min read
    Advance Java Concepts
    • Exception handling6 min read
    • Java Multithreading Tutorial3 min read
    • Synchronization in Java9 min read
    • File handling6 min read
    • Method References3 min read
    • Java 8 Stream Tutorial7 min read
    • Memory Management4 min read
    • Garbage Collection in Java6 min read
    • Networking6 min read
    • JDBC5 min read
    Practice Java
    • Interview Questions15+ min read
    • Programs6 min read
    • Practice Problems5 min read
    • Quiz1 min read
    • Project Ideas15+ min read
    Courses
    • Java Backend Course2 min read
    • Placement 360 Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.