Difference Between ArrayList and LinkedList

Google Advertisements

Prev Tutorial Next Tutorial

Difference Between ArrayList and LinkedList

ArrayList and LinkedList both are implements List interface and maintains insertion order. ArrayList and LinkedList both are non synchronized classes and these are new collection framework classes.

Note: All new Collection Framework are non-Synchronized and all Legacy Collection Framework are Synchronized.

Difference between ArrayList and LinkedList

1ArrayList 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.
3ArrayList class can act as a list only because it implements List only.LinkedList class can act as a list and queue both because it implements List and Deque interfaces.
4ArrayList is better for storing and accessing data.ArrayList is better for storing and accessing data.

Example of ArrayList and LinkedList

import java.util.*;    
class DemoArrayLinked
 public static void main(String args[])
  List<String> al=new ArrayList<String>();  //creating arraylist    
  al.add("Mark");//adding object in arraylist    
  List<String> ll=new LinkedList<String>();  //creating linkedlist    
  ll.add("Smith");  //adding object in linkedlist    
  System.out.println("Arraylist: "+al);  
  System.out.println("Linkedlist: "+ll);  


Arraylist: [Mark, Deo, Pitter, Porter]
Linkedlist: [Smith, Kater, Parker, Holly]

Prev Tutorial Next Tutorial

Download Projects

Adsense Advertisements
Free Classified Site – Bedpage

Yahoo Ads Advertisements