public class Test {
public static void main(String[] args) {
List<Integer> firstList = new ArrayList<Integer>();
for(int i=0; i<10000; i++ ){
firstList.add(i);
}
long LongtimeStart = System.currentTimeMillis();
for(int i=0; i<firstList.size(); i++ ){
System.out.println(firstList.get(i));
}
long LongtimeStop = System.currentTimeMillis();
System.out.println(" for r ============== " + (LongtimeStop-LongtimeStart));
Iterator ite = firstList.iterator();
long LongtimeStart2 = System.currentTimeMillis();
while(ite.hasNext()){
System.out.println(ite.next());
}
long LongtimeStop2 = System.currentTimeMillis();
System.out.println(" iterator r ============== " + (LongtimeStop2-LongtimeStart2));
}
}
好像 iterator 的效率 要高一点点。。。时间不够,,不确定。,。。
如果 数量多的话,就用 iterator ,如果数量 少的话,就用for ,,,不会太麻烦。、、