#* java中使用foreach语句是不是都得实现Iterator接口,数组有实现Iterator接口吗?为什么数组可以用foreach遍历。
int a[]={1,2,3,4,5,6};
for(int i:a){
System.out.println(i);
}
#* java中使用foreach语句是不是都得实现Iterator接口,数组有实现Iterator接口吗?为什么数组可以用foreach遍历。
int a[]={1,2,3,4,5,6};
for(int i:a){
System.out.println(i);
}
这里的foreach你可以看做是for的简写;
int[] a={1,2,3,4,5,6};
for(int b=0;b<a.length;b++){
System.out.println(a[b]);
}
如果回答对您有帮助,请采纳