Java ArrayList<Double> IndexOutOfBoundsException Problem
Posted
by Sebastian Bechtel
on Stack Overflow
See other posts from Stack Overflow
or by Sebastian Bechtel
Published on 2010-05-09T18:08:22Z
Indexed on
2010/05/09
18:18 UTC
Read the original article
Hit count: 501
Hello,
I've got a Problem with ArrayList. I need it to store a result. Because I want to start with element n I tryed to give the ArrayList a capacity with ensureCapacity(n+1) to use set(n,x) but I get an IndexOutOfBoundsException.
I tryed to store n add(x) before the use of set and this works.
So I'd like to know why it doesn't work on my way and how to solve this because put n times a add(x) isn't a good style ;-)
Best regards, Sebastian
© Stack Overflow or respective owner