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
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
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/java-tutorial/arraylist/arraylist_isempty.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics