93
Java Collection isEmpty() Method
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:
The queue is empty.
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.tutorAspire.JavaCollectionIsEmptyExample2.main(JavaCollectionIsEmptyExample2.java:9)
Example 3
Output:
isEmpty() method returns false Elements are : [1, 2, 3, 4, 5]
Next TopicJava Collection