Check ArrayList Empty Java
Ngày đăng:
24/01/2022
Trả lời:
0
Lượt xem:
107
Java ArrayList isEmpty()The Java ArrayList isEmpty() method checks if the arraylist is empty. Show The syntax of the isEmpty() method is: Here, arraylist is an object of the ArrayList class. isEmpty() ParametersThe isEmpty() method does not take any parameters. isEmpty() Return Value
Example: Check if ArrayList is Emptyimport java.util.ArrayList; class Main { public static void main(String[] args) { // create an ArrayList ArrayListOutput Newly Created ArrayList: [] Is the ArrayList empty? true Updated ArrayList: [Python, Java] Is the ArrayList empty? falseIn 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. |