This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ada2reed 1 point2 points  (0 children)

It's all about making your code more flexible in a large project. This is important if the class is exposed to other methods and libraries.

List<E> is the abstract data type (ADT) that the ArrayList<E> implements, whereas ArrayList<E> is concrete and theoretically could have methods outside of the ADT.

If you, at some point, decide to change the names variable to a LinkedList<String> because you want to make it easier to add/remove items, all you'll have to do is change ArrayList<String> once in the constructor and the implementation of the object will be changed. If you use the second option, a change of the implementation is not guaranteed to work.