package com.heima.test;
import java.util.ArrayList;
import java.util.Iterator;
import com.heima.bean.Person;
public class Demo1_Foreach {
public static void main(String[] args) {
demo1();
}
public static void demo1() {
//基本数据类型数组的遍历
int[] arr = {11,22,33,44,55};
for (int i : arr) {
System.out.println(i);
}
//集合的遍历
ArrayList<String> list = new ArrayList<>();
list.add("a");
list.add("b");
list.add("c");
list.add("d");
for (String string : list) {
System.out.println(string);
}
}
}
|
|