CODE:
for (int i =0; i<=10; i++) {
System.out.println(movieasArrayList.get(i).getID() + " " + movieasArrayList.get(i).getAction());
}
问题:
将此for-loop
更改为for-each loop
,以便为所有电影(不仅仅是前11位)执行相同的任务。
任何帮助将不胜感激!!
答案 0 :(得分:1)
java中的for-each循环结构如下:
// works with collections and arrays, everything
// that has an iterator
Collection<Object> c = new Collection<Object>();
for (Object i : c) {
// do code
}
对你来说,这看起来像这样:
// I don't know what your movieArrayList contains
for (Movie i : movieArrayList) {
System.out.println(i.getId() + " " + i.getAction());
}
希望这有帮助!