How do you empty an arraylist?



How do you empty an arraylist?..

Answer / Mritunjay Kumar Pandey

To empty an ArrayList, you can either use the clear() method or set its size to zero. Here are examples of both methods:
1. using clear():nArrayList<String> myList = new ArrayList<>();nmyList.add("apple");nmyList.clear();
2. setting size to zero:nArrayList<String> myList = new ArrayList<>();nmyList.add("apple");nmyList.size() = 0;

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Data Structures Interview Questions

Define an equivalence relation?

1 Answers  


What is mean by sorting?

1 Answers  


What are the main differences between the linked list and linear array?

1 Answers  


What do you mean by hash table?

1 Answers  


What are data members?

1 Answers  


Why do we study data structures?

1 Answers  


Is arraylist a collection?

1 Answers  


Is hashmap keyset ordered?

1 Answers  


What is the complexity of arraylist?

1 Answers  


What is comparable interface?

1 Answers  


Which sort is best for linked list?

1 Answers  


Q#1: An algorithm is made up of 2 modules M1 and M2.If order of M1 is F(n) and order of M2 is g (n) then what is the order of the algorithm. Q # 2 : How many binary trees are possible with 3 nodes? with 4 nodes?

4 Answers  


Categories