package com.java13.myjava;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import javax.lang.model.element.Element;
import org.junit.Test;
public class TestLinkedList {
@Test
public void test1() {
List<Integer> list = new LinkedList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
//插入
list.add(0, 5);
System.out.println(list.size());
}
@Test
public void test2() {
int Max=500000;
//构造集合 arraylist
List<Integer> list=new ArrayList<Integer>();
for(int i=0;i<=Max;i++)
{
list.add(0, i);
}
//System.out.println(System.currentTimeMillis()-startime);
//linkedlist 添加值快
List<Integer> list2=new LinkedList<Integer>();
for(int i=0;i<=Max;i++)
{
list2.add(0, i);
}
//System.out.println(System.currentTimeMillis()-startime);
long startime=System.currentTimeMillis();
list.get(Max / 2);
System.out.println(System.currentTimeMillis()-startime);
startime=System.currentTimeMillis();
list2.get(Max / 2);
System.out.println(System.currentTimeMillis()-startime);
}
@Test
public void testlinkother(){
List<String> list3=new LinkedList<String>();
list3.add(new String("TOM"));
list3.add(new String("TOM2"));
list3.add(new String("TOMsf"));
list3.add(new String("sen"));
list3.add(new String("lincd"));
list3.clear();
System.out.println(list3.size());
list3.remove(" TOM");
System.out.println(list3.size());
}
}