Java Collection isEmpty() MethodThe isEmpty() method of Java Collection Interface returns the boolean value 'true' if this collection contains no elements. SyntaxParametersNA ReturnThe isEmpty () method returns the boolean value 'true' if this collection contains no elements else it returns false. Example 1Test it NowOutput: The queue is empty. Example 2Test it NowOutput: 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.javaTpoint.JavaCollectionIsEmptyExample2.main(JavaCollectionIsEmptyExample2.java:9) Example 3Test it NowOutput: isEmpty() method returns false Elements are : [1, 2, 3, 4, 5] Next TopicJava Collection |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India