Q. What are the difference between ArrayList and LinkedList?
Ans: There are following difference between ArrayList and LinkedList:
| ArrayList | LinkedList |
| 1. ArrayList internally uses a dynamic array to store the elements. | 1. LinkedList internally uses doubly linked list to store the elements |
| 4. ArrayList is not efficient for manipulation because a lot of shifting is required. | 4. LinkedList is efficient for manipulation. |
| 5. If you do not frequently add elements at start and middle of the array and want fast random access then use Arraylist | 5. if you frequently insert element in a list and want sequential access then use Linkedlist |
| 6. ArrayList does Random Access with the help of Binary Search | 6. LinkedList does sequential access |
| 2. By default new element is added at the end of array. | 2. By default element is added as a last node.
|
| 3. Adding or Deleting a new element at start or middle of the ArrayList is very slow because all the later elements copied forward or backward. | 3. Simply create a new node and change pointers |
No comments:
Post a Comment