ArrayList<String>遍历
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("集");
list.add("合");
list.add("遍");
list.add("历");
forTravelse(list);
// list遍历-迭代器
iteratorTravelse(list);
}
private static void forTravelse(ArrayList<String> list) {
for (String str : list) {
System.out.print(str + " ");
}
System.out.println();
}
// 迭代器遍历
private static void iteratorTravelse(ArrayList<String> list) {
Iterator<String> it = list.iterator();
while (it.hasNext()) {
String next = it.next();
System.out.print(next + " ");
}
System.out.println();
}