(1) List<?> myList = new ArrayList<?>();
(2) ArrayList<?> myList = new ArrayList<?>();
Almost always the first one is preferred over the second one. The first has the advantage that the implementation of the
List can change (to a
LinkedList for example), without affecting the rest of the code. This will be a difficult task to do with an
ArrayList, not only because you will need to change
LinkedList everywhere, but also because you may have used
ArrayList specific methods.
You can read about
List implementations here. You may start with an
ArrayList, but soon afterwards discover that another implementation is more appropriate.