ArrayList学习笔记
今天学习ArrayList,比较了几种输出方式,貌似第三种效率比较高。
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
public class DateTimeInstanceDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s = "JAVA";
List<String> list = new ArrayList<String>();
for(int i = 0; i < 10000; i++){
list.add(s);
}
Date date1 = new Date();
for(int i = 0; i < list.size(); i++){
System.out.println(list.get(i) + " ");
}
Date date2 = new Date();
Iterator<String> iterator = list.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next() + " ");
}
Date date3 = new Date();
for(String string : list){
System.out.println(string + " ");
}
Date date4 = new Date();
System.out.println("开始时间:" + date1.toString());
System.out.println("消耗时间(毫秒):" + (date2.getTime()-date1.getTime()));
System.out.println("消耗时间(毫秒):" + (date3.getTime()-date2.getTime()));
System.out.println("消耗时间(毫秒):" + (date4.getTime()-date3.getTime()));
System.out.println("结束时间:" + date4.toString());
}
}