Internal datastructure
| Internally ArrayList uses a dynamic array to manipulate the record
| LinkedList works on the doubly linked list data structure.
|
Modifying the data
| Insertion and deletion in the start and middle of the array list if slow
| Insertion and deletion in the middle of the linked list is fast as comparison of LinkedList
|
Implementation
| ArrayList is implemented only List interface
| LinkedList implements both List and Deque interface
|
Searching performance
| Searching is fast in ArrayList, all its need the index position to get the desired value
| In LinkedList searching is slower, because it NEEDS to traverse the entire list
|
Complexity
| In ArrayList, the search complexity is O(1)
| In LinkedLis,t the search complexity is O(n)
|
Declare and adding the data in the list
| List<String>arrayList=new ArrayList<String>();//creating arraylist arrayList.add("Java"); arrayList.add("SPRING"); arrayList.add("Junit"); arrayList.add("jdbc");
| List<String>linkedList=new LinkedList<String>();//creating linkedlist linkedList.add("James");//adding object in linkedlist linkedList.add("Serena"); linkedList.add("Swati"); linkedList.add("JUNAID");
|
Searching of the data in the list
|
|
|
Deletion of the data in the list
|
|
|
Use case
| One can use the ArrayList when we the logic require the searching and getting off the record frequently
| One can use the LinkedList, when logic requires, frequent data insertion and deletion.
|