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));
}
}
It seems that iterator's efficiency is a little bit higher ... Time is not enough, not sure. ,。。
If the quantity is much, use iterator, if the quantity is few, use for,,, not too troublesome. 、、