package collection_test;
import java.util.ArrayList;
import java.util.Collection;
public class for_forach {
public static void main(String[] args) {
//增强for循环,专门用来遍历数组和集合
int[] arr = {1,2,3,4,5};
//使用增强for循环来遍历数组,a代表数组中的每个元素
for(int a:arr){
System.out.println(a);
}
//使用增加for循环遍历集合
Collection<String> coll = new ArrayList<>();
//添加
coll.add("科比");
coll.add("艾弗森");
coll.add("詹姆斯");
coll.add("邓肯");
coll.add("姚明");
//使用增强for循环来遍历集合,s代表集合中的每个元素
for(String s:coll){
System.out.println(s);
}
}
}
07-10
07-10
07-10
07-10
07-10
07-10
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交