ConceptDifficulty: Intermediate1 min

Two Lists With the Same Methods and Opposite Costs

Two classes implement List. They have the same methods, take the same arguments and return the same things, and swapping one for the other can turn a report that runs in a second into one that runs in a minute.

The difference is how they store what you give them.

How each list stores its elements
Compared onArrayListLinkedList
Stores elements inOne array, side by sideSeparate nodes, each pointing at the next
To find element 500Arithmetic on the addressWalk 500 links
To insert at the frontShift every element up oneChange two pointers
Memory per elementOne slotThe element plus two pointers
An array list is one contiguous block; a linked list is separate nodes joined by pointers

Neither is faster. Each is faster at the thing the other is slow at, and which of those two things your code does is not visible in the interface at all.

So this is the clearest case in the library for choosing on cost rather than on API. The methods will not tell you anything, because they are identical by design.