Java – LinkedList Collection

LinkedList:

  • LinkedList implements List
  • LinkedList allow duplicates and ordered collection.
  • Linked List store elements in the form of nodes and connect with links.
  • Accessing elements – slower in LinkedList
  • Insertions and Deletions are faster – no shifting of elements.

Methods are:

boolean add(E e)Appends the specified element to the end of this list.
void add(int index, E element)Inserts the specified element at the specified position
void addFirst(E e)Inserts the specified element at the beginning of this list.
void addLast(E e)Appends the specified element to the end of this list.
void clear()Removes all of the elements from this list.
boolean contains(Object o)Returns true if this list contains the specified element.
E get(int index)Returns the element at the specified position in this list.
E getFirst()Returns the first element in this list.
E getLast()Returns the last element in this list.
Iterator descendingIterator()Returns an iterator over the elements in this reverse.
int indexOf(Object o)Returns element index or else -1
ListIterator listIterator(int index)Create iterator from specified index.
E remove(int index)Removes the element at the specified position in this list.
E removeFirst()Removes and returns the first element from this list.
E removeLast()Removes and returns the last element from this list.
E set(int index, E element)Replace index element with specified element.
int size()Returns the number of elements in this list.
Scroll to Top