Posted as answer, as suggested:
ArrayList.get(int)
does not search. It returns directly the element addressed by the index supplied... Exactly like with an array - hence the name.
ArrayList.get(int) source:
public E get(int index) {
rangeCheck(index);
return elementData(index);
}
Where rangeCheck(int) is:
private void rangeCheck(int index) {
if (index >= size)
throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
}
And elementData() is:
E elementData(int index) {
return (E) elementData[index];
}
A Linked List would however have an O(n)
get: it would have to step to the next element until the desired index is reached...
public E get(int index) {
return entry(index).element;
}
Where entry(int) is (this is what makes it O(n)):
private Entry<E> More ...entry(int index) {
if (index < 0 || index >= size)
throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
Entry<E> e = header;
if (index < (size >> 1)) {
for (int i = 0; i <= index; i++)
e = e.next;
} else {
for (int i = size; i > index; i--)
e = e.previous;
}
return e;
}
(Note: it is double linked list, so saves some time by selecting the endpoint that is closest to the desired result, but this is still O(n) )