ArrayList clear() Method in Java with Examples
The clear() method of ArrayList in Java is used to remove all the elements from a list. The list will be empty after this call returns so do whenever this operation has been performed all elements of the corresponding Arraylist will be deleted so it does it becomes an essential function for deleting elements in ArrayList from memory leading to optimization.
Return Type: It does not return any value as it removes all the elements in the list and makes it empty.
The list initially: [1, 2, 3, 4] The list after using clear() method: