The syntax of the isEmpty() method is:
arraylist.isEmpty()
Here, arraylist is an object of the ArrayList class.
isEmpty() Parameters
The isEmpty() method does not take any parameters.
isEmpty() Return Value
- returns true if the arraylist does not contain any elements
- returns false if the arraylist contains some elements
Example: Check if ArrayList is Empty
Output
Newly Created ArrayList: [] Is the ArrayList empty? true Updated ArrayList: [Python, Java] Is the ArrayList empty? false
In the above example, we have created a arraylist named languages. Here, we have used the isEmpty() method to check whether the arraylist contains any elements or not.
Initially, the newly created arraylist does not contain any element. Hence, isEmpty() returns true. However, after adding some elements (Python, Java), the method returns false.