使用格式:
for(数据类型 变量名称 : 数组名称){……}
代码示例如下:
public class ForeachTest {
public static void print(int... temp){//可变参数是以数组的形式保存
for(int i : temp){//Java新特性foreach输出
System.out.print(i+"\t");
}
}
public static void main(String[] args) {
print(1,2,3,4,5);
}
}
从实际应用来看,还是使用原始的for循环操作最为合适