class="java"> import java.util.*; public class TestLinkedList { public static void main(String[] args) { LinkedList books= new LinkedList(); books.add("His son learns fast and well"); books.add("Good father"); books.add("Good mother"); books.add("Good grandfather"); books.add("Good grandmother!"); //System.out.println(books); books.addFirst("You're doing great, son!"); //System.out.println(books); //Object[] str= books.toArray(); //for(int i=0;i<str.length;i++){ // String book=(String)str[i]; // System.out.println(book); // Iterator it = books.descendingIterator(); Iterator it = books.listIterator(0); while(it.hasNext()){ System.out.println(it.next()); } } }
import java.util.*; public class TestPerformance { public static void main(String[] args) { String[] str= new String[90000]; for(int i=0;i<str.length;i++){ str[i]=String.valueOf(str[i]); } ArrayList list= new ArrayList(); for(int i=0;i<str.length;i++){ list.add(str[i]); } LinkedList link= new LinkedList(); for(int i=0;i<str.length;i++){ link.add(str[i]); } Long strat= System.currentTimeMillis(); for(Iterator it=list.iterator();it.hasNext();){ it.next(); } System.out.println(strat); System.out.println("截代list有的时间:"+(System.currentTimeMillis()-strat)); Long linkedstrat= System.currentTimeMillis(); for(Iterator it=link.iterator();it.hasNext();){ it.next(); } System.out.println("截代link有的时间:"+(System.currentTimeMillis()-linkedstrat)); } }