/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package listimplementations; import java.util.*; /** * * @author kvaradar */ public class ListImplementations { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here long tStart, tEnd; ArrayList aList = new ArrayList(); LinkedList lList = new LinkedList(); for (int i = 0; i < 5; i++) aList.add(i*i); System.out.println(aList); boolean b = aList.remove(new Integer(15)); aList.add(3,32); System.out.println(aList); System.out.println(b); int N = 80000; tStart = System.currentTimeMillis(); makeList2(aList, N); tEnd = System.currentTimeMillis(); System.out.println("makeList2 on Arraylist: " + (tEnd - tStart)); tStart = System.currentTimeMillis(); makeList2(lList, N); tEnd = System.currentTimeMillis(); System.out.println("makeList2 on Linkedlist: " + (tEnd - tStart)); /* tStart = System.currentTimeMillis(); sum(aList); tEnd = System.currentTimeMillis(); System.out.println("sum on Arraylist: " + (tEnd - tStart)); tStart = System.currentTimeMillis(); sum(lList); tEnd = System.currentTimeMillis(); System.out.println("sum on Linkedlist: " + (tEnd - tStart)); */ } public static void makeList1(List lst, int N) { lst.clear(); for(int i = 0; i < N; i++) lst.add(i*i); } public static void makeList2(List lst, int N) { lst.clear(); for(int i = 0; i < N; i++) lst.add(0, i*i); } public static int sum(List lst){ int total = 0; int N = lst.size(); for (int i = 0; i < N; i++) total += lst.get(i); return total; } }