Difference between ArrayList and LinkedList

ArrayList and LinkedList both implements List interface and maintains insertion order. Both are non synchronized classes.

SN ArrayList LinkedList
1 ArrayList internally uses dynamic array to store the elements. LinkedList internally uses doubly linked list to store the elements
2 Manipulation with ArrayList is slow because it internally uses array. If any element is removed from the array, all the bits are shifted in memory Manipulation with LinkedList is faster than ArrayList because it uses doubly linked list so no bit shifting is required in memory.
3 ArrayList class can act as a list only because it implements List only.x LinkedList class can act as a list and queue both because it implements List and Deque interfaces
4 ArrayList is better for storing and accessing data. LinkedList is better for manipulating data.

Program ArrayList and LinkedList in Java

1.	import java.util.*; 

2.	class DemoArrayLinked{ 

3.	public static void main(String args[]){ 


5.	List al=new ArrayList();//creating arraylist 

6.	al.add("Neha");//adding object in arraylist 

7.	al.add("Raju"); 

8.	al.add("Neha"); 

9.	al.add("Ravi"); 


11.	List al2=new LinkedList();//creating linkedlist 

12.	al2.add("Vijay");//adding object in linkedlist 

13.	al2.add("Himanshu"); 

14.	al2.add("Swati"); 

15.	al2.add("Rahul"); 


17.	System.out.println("arraylist: "+al); 

18.	System.out.println("linkedlist: "+al2); 

19.	} 

20.	} 


arraylist: [Neha,Raju,Neha,Ravi]

linkedlist: [Vijay,Himanshu,Swati,Rahul]