ArrayList 和LinkedList

package test1;

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

/**
 * Created by Administrator on 2017/6/3 0003.
 */
public class ListPK {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        Object object1 = new Object();
        long start = System.currentTimeMillis();
        for(int i=0;i<5000000;i++) {
            list.add(object1);
        }
        long end = System.currentTimeMillis();
        System.out.println(end-start);

        LinkedList list1 = new LinkedList();
        Object object2 = new Object();
        start = System.currentTimeMillis();
        for(int i=0;i<5000000;i++) {
            list1.add(object1);
        }
        end = System.currentTimeMillis();
        System.out.println(end-start);

        start = System.currentTimeMillis();
        for(int i=0;i<100000;i++) {
            list.add(object1);
        }
        end = System.currentTimeMillis();
        System.out.println(end-start);

        start = System.currentTimeMillis();
        for(int i=0;i<100000;i++) {
            list1.add(object2);
        }
        end = System.currentTimeMillis();
        System.out.println(end-start);

        start = System.currentTimeMillis();
        list.add(1,1);
        end = System.currentTimeMillis();
        System.out.println(end-start);

        start = System.currentTimeMillis();
        list1.add(1,1);
        end = System.currentTimeMillis();
        System.out.println(end-start);

    }
}

 

posted @ 2017-06-03 21:43  danawill  阅读(140)  评论(0编辑  收藏  举报