Last Updated :
10 Apr, 2024
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(3);
list.add(4);
list.add(5);
list.add(6);
System.out.print(list.size() + \" \");
list.clear();
System.out.print(list.size());
Output of the above program.
(A) 4 0
(B) 4 4
(C) 4 3
(D) None of the mentioned
Answer: (A)
Explanation: size(): returns the size of the arraylist which gives 3(here).
clear(): removes all the elements from the arraylist.
Share your thoughts in the comments
Please Login to comment...