Collection of bad coding practices

Posts Tagged ‘list

LinkedLists as arrays

leave a comment »

java.util.LinkedList is a special type of collection designed for sequential access (stacks and queues). Being used as a random-accesed array, it is much slower than other List implementations. For instance, getting an item by index (get(n)) has constant complexity O(1) for ArrayLists, while for LinkedList, the complexity of that operation is O(n).

Use ArrayList (or Vector if synchronization is required) for random-accessed lists.


Written by Alex

November 22, 2007 at 1:03 pm

Posted in Collections

Tagged with , ,