posted 16 years ago
ArrayList uses an array as its backing storage. When you add something at index 9, it has to shift the element at position 9 up by one. That's one element. When you add something at index 2, it has to shift the elements at positions 2 and higher up by one. That's 8 elements initially.
LinkedList will not shift anything but instead just puts a new link in between. That is equally fast regardless of the position. However, it first must find the position, and that will take (just a bit) longer for index 2. That might surprise you, but LinkedList knows that 9 is nearer to its end than to its start so it will go backwards from the end.