package com.fuxi.test.collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class LinkedListTest {
public static void main(String[] args) {
List<Student> list = new LinkedList<Student>();
for(int i = 0;i<100;i++){
list.add(new Student("I am"+i));
}
Iterator<Student> it = list.iterator();
long time1 = System.currentTimeMillis();
while(it.hasNext()){
Student stu = it.next();
System.out.println(stu.getName());
}
long time2 = System.currentTimeMillis();
System.out.println("用iterator遍历链表用时:"+(time2-time1));
long time3 = System.currentTimeMillis();
for(int i =0;i<list.size();i++){
Student stu = list.get(i);
System.out.println(stu.getName());
}
long time4 = System.currentTimeMillis();
System.out.println("用for循环遍历链表用时:"+(time4-time3));
}
}
class Student{
String name;
public Student(String name){
this.name = name;
}
public String getName(){
return name;
}
}