Why java.lang.IndexOutOfBoundsException is raised in this example, if the size of ArrayList has been predefined? How to solve this problem?
int size = 2: ArrayList<Integer[]> nums = new ArrayList<Integer[]>(size); Integer[] value1 = {1,2,3}; Integer[] value2 = {1,2}; nums.add(1,value1); // java.lang.IndexOutOfBoundsException nums.add(0,value2);