Q- What is the difference between ArrayList and LinkedList?
ArrayList | LinkedList |
---|---|
ArrayList uses dynamic array to store
elements internally. ArrayList implements a List interface. Therefore, this acts as a list. |
LinkedList uses doubly Linked List to
store elements internally. LinkedList implements the List interface and the Deque interface. Therefore, it can act as a List, Stack and Queue. |
ArrayList is slower then
LinkedList due to the internal
implementation. if we insert or delete an
element, internally, the array is
traversed and the memory bits are
shifted. And it may take O(n) |
ArrayList if we insert or delete
element because, in a doubly-linked
list, there is no concept of shifting
the memory bits. The list is traversed
and the reference link is changed. it will take O(1), as it internally uses doubly LinkedList |
Storing and accessing the data,
is faster in ArrayList as uses array
internally. which is index based. So here time complexity is O(1) |
Search is slower in LinkedList as uses
doubly Linked List internally So here time complexity is O(n) |
Manipulation with ArrayList is slow. | It give better performance for Manipulation of the stored data. |
The memory location for the elements of an ArrayList is contiguous. | The location for the elements of a linked list is not contagious. |
The default capacity of ArrayList is 10 | There is no case of default capacity in a LinkedList. In LinkedList, an empty list is created when a LinkedList is initialized. |
ArrayList is a resizable array. | No need to resize. It will create new node and add. |
Related Tutorials
- Java Collections Interview
- List Interface In Java
- ArrayList
- LinkedList
- Custom Own ArrayList Implementation
- Custom LinkedList implementation in java
- Set Interface In Java
- Map Interface In Java
- HashMap
- TreeMap
- HashMap Vs ConcurrentHashMap
- HashMap Vs HashTable In Java
- HashMap Vs HashSet In Java
- HashMap Vs TreeMap In Java
- HashMap vs LinkedHashMap In Java
- TreeSet Vs TreeMap In Java
- SortedSet Vs TreeSet In Java
- SortedMap Vs TreeMap In Java
- Array Vs ArrayList In Java
- ArrayList Vs LinkedList In Java
- How HashSet Works Internally
- How TreeMap Works Internally
- How HashMap Works Internally
- How ConcurrentHashMap Works Internally
- How To Detect Loop In A LinkedList In Java
- Detect And Remove Loop In A LinkedList
No comments:
Post a Comment