http://stackoverflow.com/questions/85190/how-does-the-java-for-each-loop-work 引用此頁的資料 for(Iterator<String> i = someList.iterator(); i.hasNext(); ) { String item = i.next(); System.out.println(item); } Note that if you need to use i.remove(); in your loop, or access the actual iterator in some way, you cannot use the for( : ) idiom, since the actual Iterator is merely inferred. As was noted by Denis Bueno, this code works for any object that implements the
read more