日期:2014-05-20 浏览次数:20648 次
import java.util.*; class Student{ String name; Student(String name){ this.name=name; } public String getName(){ return name; } } public class LinkedList { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub List<Student> list=new LinkedList<Student>(); for(int k=1;k<=100;k++){ list.add(new Student("I am "+k)); } Iterator<Student> iter=list.iterator(); long time1=System.currentTimeMillis(); while (iter.hasNext()){ Student te=iter.next(); System.out.println(te.getName()); } long time2=System.currentTimeMillis(); System.out.println("用时"+(time2-time1)+"毫秒"); } }
import java.util.*; class Student{ String name; Student(String name){ this.name=name; } public String getName(){ return name; } } public class LinkedListTest { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub List<Student> list=new LinkedList<Student>(); for(int k=1;k<=100;k++){ list.add(new Student("I am "+k)); } Iterator<Student> iter=list.iterator(); long time1=System.currentTimeMillis(); while (iter.hasNext()){ Student te=iter.next(); System.out.println(te.getName()); } long time2=System.currentTimeMillis(); System.out.println("用时"+(time2-time1)+"毫秒"); } }