2 Star 0 Fork 0

20165203Enosh / 20165203xyx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Example15_2.java 842 Bytes
一键复制 编辑 原始数据 按行查看 历史
20165203Enosh 提交于 2018-04-08 19:28 . week6
import java.util.*;
public class Example15_2 {
public static void main(String args[]){
List<String> list=new LinkedList<String>();
for(int i=0;i<=60096;i++){
list.add("speed"+i);
}
Iterator<String> iter=list.iterator();
long starttime=System.currentTimeMillis();
while(iter.hasNext()){
String te=iter.next();
}
long endTime=System.currentTimeMillis();
long result=endTime-starttime;
System.out.println("使用迭代器遍历集合所用时间:"+result+"毫秒");
starttime=System.currentTimeMillis();
for(int i=0;i<list.size();i++){
String te=list.get(i);
}
endTime=System.currentTimeMillis();
result=endTime-starttime;
System.out.println("使用get方法遍历集合所用时间:"+result+"毫秒");
}
}
Java
1
https://gitee.com/xyx-nice/20165203xyx.git
git@gitee.com:xyx-nice/20165203xyx.git
xyx-nice
20165203xyx
20165203xyx
master

搜索帮助