Overhead matters a lot more when you're dealing with larger amounts of data. ArrayLists will do things like resize the internal container which can result in using more space than necessary and also takes CPU cycles. Also ArrayLists can't hold primitives, which adds extra overhead (an Integer is larger than an int).
Let's compare an array of a million ints to an ArrayList of a million Integers. Borrowing dwell's sizeOf() method:
Code:
static final int MILLION = 1000000;
public static void main(String[] args) throws Exception {
int[] array = new int[MILLION];
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < MILLION; ++i) {
array[i] = i;
list.add(i);
}
System.out.println(sizeOf(array));
System.out.println(sizeOf(list));
}
Output:
The ArrayList is 2.5x larger.
The int[] takes 3.8 MB and the ArrayList takes 9.5 MB. In a larger applicaiton, that really adds up. It could be the difference between your program using 400MB or 1000MB.