Collection isEmpty()
Java Collection isEmpty() Method
Last Updated : 17 Mar 2025
The isEmpty() method of Java Collection Interface returns the boolean value 'true' if this collection contains no elements.
Syntax
Parameters
NA
Return
The isEmpty () method returns the boolean value 'true' if this collection contains no elements else it returns false.
Example 1
Output:
Example 2
Output:
Exception in thread "main" java.lang.NullPointerException at java.util.concurrent.ConcurrentLinkedQueue.checkNotNull(ConcurrentLinkedQueue.java:920) at java.util.concurrent.ConcurrentLinkedQueue.offer(ConcurrentLinkedQueue.java:327) at java.util.concurrent.ConcurrentLinkedQueue.add(ConcurrentLinkedQueue.java:297) at com.tpointtech.JavaCollectionIsEmptyExample2.main(JavaCollectionIsEmptyExample2.java:9)
Example 3
Output:
isEmpty() method returns false Elements are : [1, 2, 3, 4, 5]