循環是有兩種類型的在Java
int[] numbers = {1,2,3,4,5,6,7,8,9,10};
for (int item : numbers) {
System.out.println("Count is: " + item);
}
和
int[] numbers = {1,2,3,4,5,6,7,8,9,10};
for (int i = 0; i < 10; i++) {
System.out.println("Count is: " + numbers[i]);
}
http://docs.oracle.com/javase/1.5.0/docs/guide/language/foreach.html – kosa
@John check out http://stackoverflow.com/questions/2113216/which-is-more -efficient for a each-loop-or-an-iterator :) – WilliamShatner