Can anyone explain how remove()
of ArrayList
works?
public class ListTest {
public static void main(String[] args) {
List list = new ArrayList();
for(int i=0;i<10;i++)
{
list.add(i);
}
System.out.println("Size of list before removing :"+list.size());
for(int i=0;i<list.size();i++)
{
list.remove(i);
}
System.out.println("Size of list after removing all elements :"+list.size());
}
}
Output
Size of list before removing: 10
Size of list after removing all elements: 5
What am I doing wrong?