According to javadoc , when you write
ArrayList<Integer[]> nums = new ArrayList<Integer[]>(size);
You do not determine the number the size of the number, you determine the initial capacity . In this sense, ArrayLists are not like inline arrays (value1 and value2 in your code).
You can try it yourself: print the nums size after each line (the code is cleared to prevent an IndexOutOfBoundsException.
int size = 2: ArrayList<Integer[]> nums = new ArrayList<Integer[]>(size); Integer[] value1 = {1,2,3}; Integer[] value2 = {1,2}; System.out.println(nums.size()); nums.add(value2); System.out.println(nums.size()); nums.add(value1); System.out.println(nums.size());
This will print:
0 1 2
source share