Hi guys i catch exception:
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
Code look like this:
**ArrayList decoded = new ArrayList(10);
decoded.add(1, "A");**
I really don’t get it what’s wrong here ?
Maybe someone could help me on this.
Basically i want to do this:
I have chars for example likes this:
ABCEDFG
And array with numbers:
321211
I need to take first char and first number. char write into S arrayList:
S={"A"};
Look at number and again write same char in that position if number is 3 then in third place:
(If number 1 then just write it in arrayList)
S={"A","","","A"}
And delete number and char from arrayLists. Now they look like this:
BCEDFG
21211
and again the same till the end.
I suspect you’re confused between capacity and size. This line:
… creates a list with a capacity of 10 (it won’t need to grow internally until the eleventh element is added), but a size of 0. The only index you can add anything is 0.
If you want to be able to set values at arbitrary positions, you should populate the list first, e.g. (using generics just because I hate using the raw types):
Alternatively, if you already know the size you want, you could use an array to start with – they have a fixed size, and each element is the default value for the element type (so
nullfor strings, for example):