Difference Between ArrayList and LinkedList

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

ArrayListLinkedList
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    
  al.add("Deo");
  al.add("Pitter");
  al.add("Porter");
    
  List<String> ll=new LinkedList<String>();  //creating linkedlist    
  ll.add("Smith");  //adding object in linkedlist    
  ll.add("Kater");    
  ll.add("Parker");    
  ll.add("Holly");    
 
  System.out.println("Arraylist: "+al);  
  System.out.println(".........................");  
  System.out.println("Linkedlist: "+ll);  
 }    
}   

Output

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

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements