ArrayList arrayList = new ArrayList();
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);
// 增强foreach
arrayList.forEach(obj -> System.out.println(obj));
// 转化为数组,然后对数组遍历
// 转化成数组
Object[] array = arrayList.toArray();
// 数组遍历
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
// Iterator遍历
Iterator iterator = arrayList.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}