4/17/19

Difference between Array List and Linked List | Java Collections Framework (JCF) Part -6



import java.util.ArrayList;
import java.util.LinkedList;

public class ArrayListVSLinkedList {

    public static void main(String[] args) {

      long startTimeA = System.currentTimeMillis();

      for(int i=0;i<1000;i++){
          ArrayList al =new ArrayList();
          al.add(i);
      }

      long endtimeA =  System.currentTimeMillis();

      System.out.println("ArrayList Time is "+(endtimeA-startTimeA)+"ms");


      long startTimeL = System.currentTimeMillis();

      for (int i=1;i<1000;i++){
          LinkedList ll = new LinkedList();
          ll.add(i);
      }

    long endtimeL =  System.currentTimeMillis();

    System.out.println("LiknedList Time is "+(endtimeL-startTimeL) +"ms");

    }
}


Note: Red color denoted by ArrayList, Green color denotes by LinkedList.

No comments:

Post a Comment

About

Hi, I'm Najathi.
I've started entrepreneurial company, Twin Brothers.Inc.
One is self-funded & the other is venture backed. I also send a weekly. where I share relevent, curated links.

Every Week I Publish a short post on writing, publishing, or content of IT Related

Contact Form

Name

Email *

Message *