VOOZH about

URL: https://www.geeksforgeeks.org/java/collection-isempty-method-in-java-with-examples/

⇱ Collection isEmpty() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Collection isEmpty() method in Java with Examples

Last Updated : 24 Jul, 2024

The isEmpty() of java.util.Collection interface is used to check if the Collection upon which it is called is empty or not. This method does return a boolean value indicating whether the collection is empty or not. Here's the correct information for the isEmpty() method:

Syntax:

boolean isEmpty()

Parameters:

This method does not accept any parameter.

Return Value:

This method returns a boolean value, which indicates whether the collection is empty or not. The below examples illustrate the Collection isEmpty() method:

Example 1: Using LinkedList Class


Output
The list is: [Geeks, for, Geeks]
Is the LinkedList empty: false
The new List is: []
Is the LinkedList empty: true


Example 2: Using ArrayDeque Class


Output
ArrayDeque: [Welcome, To, Geeks, 4, Geeks]
Is the ArrayDeque empty: false
The new ArrayDeque is: []
Is the ArrayDeque empty: true


Example 3: Using ArrayList Class


Output
ArrayList: [15, 20, 25]
Is the ArrayList empty: false
The new ArrayList is: []
Is the ArrayList empty: true

Reference:

https://docs.oracle.com/javase/9/docs/api/java/util/Collection.html#isEmpty--
Comment