9 ms·
Agreed that LinkedList memory footprint and locality are serious issues. Fundamentally though the problem is that the LinkedList implementation is at odds with
by smarks 4y ago
Agreed that LinkedList memory footprint and locality are serious issues.
Fundamentally though the problem is that the LinkedList implementation is at odds with the abstraction provided by List -- access by index.
Certainly, straight iteration of every element is better done by a for-each loop (which uses an Iterator under the covers). But the availability of indexed access leads one to use it for a variety of additional circumstances. Consider for example processing every even-numbered element, or finding an element that meets some criterion and then operating on an adjacent element. Iterating over indexes for cases like these is quite natural given the List API. (ListIterator can be used for this sort of stuff, but it's quite cumbersome, and sometimes it doesn't actually help.)