1、遍历循环
for (循环变量类型 循环变量名称;循环条件;更新语句) 循环体
String[] arr = { "a", "b", "c", "d" }; for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } 打印台 a b c d
2、迭代器循环
String[] arr = { “a”, “b”, “c”, “d” };
List<String> list = Arrays.asList(arr);
for (Iterator<String> iterator = list.iterator();iterator.hasNext();)
{
System.out.println(iterator.next());
}
控制台信息
a
b
c
d
3、增强型for循环
for (循环变量类型 循环变量名称 : 要被遍历的对象) 循环体
String[] arr = { “a”, “b”, “c”, “d” };
for (String a : arr) {
System.out.println(a);
}
控制台
a
b
c
d