What are the differences between ArrayList and LinkedList types in Java ?
![]() Don't want to miss a single bit? Subscribe By Email for Daily Jobs |
Order is the most important feature of a List; it promises to maintain elements in a particular sequence. List adds a number of methods to Collection that allow insertion and removal of elements in the middle of a List. (This is recommended only for a LinkedList.) A List will produce a ListIterator, and by using this you can traverse the List in both directions, as well as insert and remove elements in the middle of the List.
ArrayList
A List implemented with an array. Allows rapid random access to elements, but is slow when inserting and removing elements from the middle of a list. ListIterator should be used only for back-and-forth traversal of an ArrayList, but not for inserting and removing elements, which is expensive compared to LinkedList.
LinkedList
Provides optimal sequential access, with inexpensive insertions and deletions from the middle of the List. Relatively slow for random access. (Use ArrayList instead.) Also has addFirst( ), addLast( ), getFirst( ), getLast( ), removeFirst( ), and removeLast( ) (which are not defined in any interfaces or base classes) to allow it to be used as a stack, a queue, and a deque.
Related Articles
- What are containers in C++ and in Object Oriented Programming ? Which objects are available as containers ?
- How do you find the middle of a linked list? Write a C program to return the middle of a linked list
- What are Vectors in C++(Object Oriented Programming) and how are they used ?
- What is the difference between List and List
(not parametrized list and list parametrized by String) in Java ? - What are the difference between Set and List.in Java ?


