for (type var : arr) { body-of-loop }
for (int i = 0; i < arr.length; i++) { type var = arr[i]; body-of-loop }
for (type var : coll) { body-of-loop }
for (Iterator<type> iter = coll.iterator(); iter.hasNext(); ) { type var = iter.next(); body-of-loop }
Altho the enhanced for loop can make code much clearer, it can't be used in some common situations.
看来只能读取, 而不能写入值。而且不能进行太复杂的操作。
Powered by: BlogJava Copyright © kooyee