答案 0 :(得分:2)
答案 1 :(得分:0)
for (File file : files)
- 在Java中是foreach循环,与for each file in files
相同。其中files
是可迭代的,file
是变量,其中每个元素临时存储有for循环范围。见http://docs.oracle.com/javase/1.5.0/docs/guide/language/foreach.html
答案 2 :(得分:0)
这表示对于一组文件中的每个文件都执行...(正文)
了解详情The For-Each Loop。链接中的例子很棒。
答案 3 :(得分:0)
- 这种形式的循环来自1.5
的Java,并且被称为For-Each Loop
。
让我们看看它是如何运作的:
For Loop:
int[] arr = new int[5]; // Put some values in
for(int i=0 ; i<5 ; i++){
// Initialization, Condition and Increment needed to be handled by the programmer
// i mean the index here
System.out.println(arr[i]);
}
For-Each循环:
int[] arr = new int[5]; // Put some values in
for(int i : arr){
// Initialization, Condition and Increment needed to be handled by the JVM
// i mean the value at an index in Array arr
// Its assignment of values from Array arr into the variable i which is of same type, in an incremental index order
System.out.println(i);
}