Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将增强的for循环转换为for循环_Java - Fatal编程技术网

Java 将增强的for循环转换为for循环

Java 将增强的for循环转换为for循环,java,Java,如何将下面的“增强for循环”转换为“for循环” ArrayList<Integer> input= new ArrayList<Integer>(); int[] copies = new int[20]; for(int allCopies : input) { copies[allCopies]++; } 但我们不知道如何得到这部分: for(int allCopies : input) { copies[allCopies]++;

如何将下面的“增强for循环”转换为“for循环”

ArrayList<Integer> input= new ArrayList<Integer>();

int[] copies = new int[20];
 for(int allCopies : input) {
        copies[allCopies]++;
    }
但我们不知道如何得到这部分:

for(int allCopies : input) {
copies[allCopies]++;
任何帮助?????

ArrayList input=new ArrayList();
ArrayList<Integer> input= new ArrayList<Integer>();

int[] copies = new int[20];
for(int k = 0; k < input.size(); k++) {
    copies[input.get(k)]++;
}
int[]份数=新int[20]; 对于(int k=0;k
在增强的for循环中
for(int-allCopies:input)

所有副本
输入[对位]
相同

因此,基本上所有这些都是使用
k
作为计数器来获取该值

input.get(k)

这应该可以做到:

int allCopies = input.get(k);
您应该查看第一个以找到合适的使用方法。

copies[input.get(k)]++;
int allCopies = input.get(k);
copies[input.get(k)]++;