public class MyListTest {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
for (int i = 0; i <=8; i++) {
list.add("考試加油"+i);
}
//第一種循環(huán)方式
for (int i = 0; i < list.size(); i++) {
System.out.print(""+list.get(i)+",");
}
System.out.println();
//第二種循環(huán)方式
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
String string = iterator.next();
System.out.println(string);
}
}
}
結(jié)果如下: