A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/java-tutorial/arraylist/arraylist_isempty.php below:

Website Navigation


Java arraylist isempty Method - w3resource

Java ArrayList.isEmpty() MethodLast update on August 19 2022 21:51:25 (UTC/GMT +8 hours) 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

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4