artouiros artouiros - 7 months ago 78
Java Question

Java ArrayList clear() function

Let's say I have a

ArrayList<String> data;

I'm adding some data into this Array, using
Let's say I've added 10 Strings into this array. The size of the array is 10 now.

How do i destroy all elements in the array? The
function just set's all 10 elements to null. So when I try to add another element, it just get's on the 11 position. I want just to start it over from 0;

I can use a for loop to replace all the data, but I really think there is a way just to empty the
. Is it?

Dan Dan

Your assumptions don't seem to be right. After a clear(), the newly added data start from index 0.