I need a array object, that should holds 3 Objects.
At first was using Collection, but I need to add to a specific place. for example:
CollectionObject.add(pos, myObject)
Then I went to ArrayList, created object like this:
ArrayList<MyObject> array = new ArrayList<MyObject>();
When creating this, it creats array with size 1, but I need to add to position 0-2, so adding like:
array.add(2, myObject)
I got :
java.lang.IndexOutOfBoundsException: Index: 2, Size: 1
My solution is, create arraylist, add 3 empty objects to it, and later overwrite, but any more subtle solution? Are there any better array holding objects, like Vector or something?
Use an array of 3 elements instead as follows: