Back to index
Marker interface used to inform
List implementations that they support fast (usually constant time) random access.
This allows generic list algorithms to tailor their behavior based on the list type.
For example, some sorts are n*log(n) on an array, but decay to quadratic time on a linked list. As a rule of thumb, this interface should be used is this loop:
for (int i = 0, n = list.size(); i < n; i++) list.get(i);
runs faster than this loop:
for (Iterator i = list.iterator(); i.hasNext(); ) i.next();