In the first line, we create an empty List of String type. Then, we check whether the list is empty or not using the isEmpty() method. It returns true, as the list is empty.
Then, we add a fruit "apple" to the list using the add() method. Now, when we call the isEmpty() method on this list, it returns false as the list is not empty.
Finally, we clearing the list using the clear() method, and calling isEmpty() again, which returns true as the list is empty again.
Java List interface and its implementations are part of the java.util package. So, the code above uses java.util.ArrayList class.
Java List.isEmpty - 30 examples found. These are the top rated real world Java examples of List.isEmpty from package OpenDSA-server extracted from open source projects. You can rate examples to help us improve the quality of examples.