How can I initialize an ArrayList with all zeroes in Java?

It looks like arraylist is not doing its job for presizing:

// presizing 

ArrayList<Integer> list = new ArrayList<Integer>(60);

Afterwards when I try to access it:

list.get(5) 

Instead of returning 0 it throws IndexOutOfBoundsException: Index 5 out of bounds for length 0.

Is there a way to initialize all elements to 0 of an exact size like what C++ does?

5 Answers
5

Leave a Comment