1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* Remove all elements from Java ArrayList Example This Java Example shows how to remove all elements from java ArrayList object using clear method. */ import java.util.ArrayList; public class RemoveAllElementsOfArrayListExample { public static void main(String[] args) { //create an ArrayList object ArrayList arrayList = new ArrayList(); //Add elements to Arraylist arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); System.out.println("Size of ArrayList before removing elements : " + arrayList.size()); /* To remove all elements from the ArrayList use void clear() method. */ arrayList.clear(); System.out.println("Size of ArrayList after removing elements : " + arrayList.size()); } } /* Output would be Size of ArrayList before removing elements : 3 Size of ArrayList after removing elements : 0 */ |
?????????
Thank for info