每个使用Iterator的For循环(使用Iterator.remove();方法)如下所示:
for (Iterator<E> iter = list.iterator(); iter.hasNext(); ) {
E element = iter.next();
//some code
}
Run Code Online (Sandbox Code Playgroud)
基本的循环样式:
for([initial statement]; [loop condition]; [iterating statement]) {/*Some Code*/}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是......为什么他们从未写过
for (Iterator<E> iter = list.iterator(); iter.hasNext(); E element = iter.next()) {
//some code
}
Run Code Online (Sandbox Code Playgroud)