Java 将增强的for循环转换为for循环
如何将下面的“增强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]++;
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)]++;