自己对java中增强for循环的理解,因自己经常搞混,记录下来。
public class Fors { public static void main(String [] args) { Something s=new Something(); s.test(); } } class Something { public void test() { int arg[]={1,2,3,4,5}; /* int i=0; */ for (int num : arg) //增强for循环,遍历数组。 { System.out.println(num); } /* 等价于 for (i=0;i<arg.length;i++){ System.out.println(arg[i]); } */ } }
题外话: 网页设计中在<pre>标签中出现“<”等的一些特殊符号时,需要对其进行转义,否则的话写出的内容显示不完整。