Java List Efficiency

Java List efficiency
I found this nice cheat sheet for Java collections.

As you can see, ArrayList is most efficient when doing lots of adding and reading to/from a list. This is because an ArrayList allows for direct access, while the implementation of a LinkedList does not allow this.

If possible (that is if you do not need the methods provided by a specific list implementation), a list should always be declared via its interface (as this enables to easily adjust the program):

If iterating over this list, if possible the Iterator interface should be used. This is better than using a for loop with list.get(i), because if you do decide to change the list to e.g. a LinkedList later on, the Iterator is a lot more efficient (get(i) on LinkedList would take O(i), next() on Iterator O(1)).
Iterator iterator = list.iterator();
while(iterator.hasNext()) {
     next =;
    // do stuff with next

Related Posts:

Leave a Reply

Your email address will not be published.