一:为什么要用增强版的 for 循环呢
在普通的数组遍历当中,我们采用普通的for循环即可,但在遍历2.遍历集合、容器,当中我们一般采用增强版的for循环 ,简单方便。
二:构造模式
for(数据类型 变量:定义的数组或容器的名称)
三:举例
示例一:
int a[] = {1,2,3,4,5};
for( int temp:a)
System.out.println(temp);
示例二:
List<String> list = new ArrayList<String>();
list.add("aa");
list.add("bb");
list.add("cc");for(String temp:list)
System.out.println(temp);