List

List is an interface that extends Collection, allows duplicates, and provides control over ordering.

  • The most common methods used are add(), get(), remove(), set().
  • Searching is done through indexOf() for the first occurrence of the argument object and lastIndexOf() for the last occurrence.

  • ArrayList

  • Implements List backed by an array.
  • Not thread safe.

  • LinkedList

  • Implements both List and Deque interfaces.
  • No reason to use it as a list unless there is a need to insert elements anywhere other than at the end of the list. LinkedList will be faster for mid-inserts than ArrayList.

  • CopyOnWriteArrayList

  • Implements List.
  • Part of the java.util.concurrent package, so it’s thread-safe.
  • Use if writes are infrequent. Otherwise, use a synchronized wrapper around ArrayList or LinkedList.
  • You must be logged in to post a comment.