1.Iterable
2.Iterator
3.使用
List<Integer> list = new ArrayList<>();
list.add(5);
list.add(23);
list.add(42);
#普通遍历
for (int i = 0; i < list.size(); i++) {
System.out.print(list.get(i) + ",");
}
#涉及到了 iterator
Iterator it = list.iterator();
while (it.hasNext()) {
System.out.print(it.next() + ",");
}
#涉及到了 iterable
for (Integer i : list) {
System.out.print(i + ",");
}