从JAVA5开始出现了增强for循环,可用来方便的迭代数组中的元素,而不涉及其下标
String[] names = {"well","tom","lily","lucy"}; for (String n : names) { System.out.println(n); }
输出结果为:
well tom lily lucy
格式:
for(元素数据类型 变量名 :数组对象或Iterator对象){
//方法体,用来操作变量
}
从JAVA5开始出现了增强for循环,可用来方便的迭代数组中的元素,而不涉及其下标
String[] names = {"well","tom","lily","lucy"}; for (String n : names) { System.out.println(n); }
输出结果为:
well tom lily lucy
格式:
for(元素数据类型 变量名 :数组对象或Iterator对象){
//方法体,用来操作变量
}