Source Code : Add to start Performance compare: LinkList and ArrayList

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Add to start Performance compare: LinkList and ArrayList

       
/*
time for LinkedList = 62
time for ArrayList = 7488
*/
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class ListDemoHead {
  static final int SIZE = 100000;

  static long timeList(List list) {
    long start = System.currentTimeMillis();
    Object obj = new Object();
    for (int i = 0; i < SIZE; i++) {
      // add object to the head of the list
      list.add(0, obj);
    }

    return System.currentTimeMillis() - start;
  }

  public static void main(String args[]) {
    // do timing for LinkedList
    System.out.println("time for LinkedList = " + timeList(new LinkedList()));

    // do timing for ArrayList
    System.out.println("time for ArrayList = " + timeList(new ArrayList()));
  }
}

           
         
    
    
    
    
    
    
  

Thank with us