我可以使用每种语法从数组中读取数据:
int[] a = new int[100];
for (int i = 0; i < 100; i++){
a[i] = i;
}
for (int element : a){
System.out.println(element);
}
Run Code Online (Sandbox Code Playgroud)
但同样可以填充阵列.说,有i*2价值观?
我没有发明这样的方法,而是宁愿问你我是不是错了.
来自Java Docs,
for-each循环隐藏了迭代器,因此您无法调用remove.因此,for-each
loop is not usable for filtering. Similarly it is not usable for loops where you need to replace elements in a list or array as you traverse it. Finally, it is not usable for loops that must iterate over multiple collections in parallel. These shortcomings were known by the designers, who made a conscious decision to go with a clean, simple construct that would覆盖绝大多数情况.
所以,简单来说,它不可能填充数组.
| 归档时间: |
|
| 查看次数: |
2364 次 |
| 最近记录: |