Monday, August 3, 2015

Java :Lists Vs ArrayLists

Lists Vs ArrayLists

List<?> myList = new ArrayList<?>();

ArrayList<?> myList = new ArrayList<?>();


  • List is an interface and ArrayList is an implementation of the List interface.
  • There is no much of a difference except for the basic polymorphism concept that if you use Lists then you will only able to use methods of only Lists type but if you use ArrayList you should be able to use methods from ArrayList as well as from Lists and Overridden methods by ArrayLists if any.
  •  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 ArrayList to LinkedList everywhere, but also because you may have used ArrayList specific methods.

No comments:

Post a Comment