• Martin Thoma
  • Home
  • Categories
  • Tags
  • Archives
  • Support me

What can ArrayList / LinkedList do what List can't?

I've told my students to write

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

instead of

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

as this allows them to switch to any Class that implements List without having to change more code.

This does always make sense, except if you need methods from ArrayList or LinkedList. But which methods does ArrayList / LinkedList offer that List doesn't have?

ArrayList has:

  • Object clone()
  • void ensureCapacity(int minCapacity)
  • void removeRange(int fromIndex, int toIndex)
  • void trimToSize()

LinkedList has:

  • void addFirst(E e)
  • void addLast(E e)
  • Object clone()
  • Iterator descendingIterator()
  • E getFirst()
  • E getLast()
  • boolean offer(E e)
  • boolean offerFirst(E e)
  • boolean offerLast(E e)
  • E peek()
  • E peekFirst()
  • E peekLast()
  • E poll()
  • E pollFirst()
  • E pollLast()
  • E pop()
  • void push(E e)
  • E removeFirst()
  • boolean removeFirstOccurrence(Object o)
  • E removeLast()
  • boolean removeLastOccurrence(Object o)

Published

Feb 4, 2013
by Martin Thoma

Category

Code

Tags

  • Java 36

Contact

  • Martin Thoma - A blog about Code, the Web and Cyberculture
  • E-mail subscription
  • RSS-Feed
  • Privacy/Datenschutzerklärung
  • Impressum
  • Powered by Pelican. Theme: Elegant by Talha Mansoor