我有一個列表:名單VS列表迭代器
List<Object> myList = new ArrayList<Object>();
要從此列表中獲取有兩種方法:
1.
for(Object obj : myList)
{
// some code
}
2.
Iterator<Object> objIt = myList.iterator();
while(obj.hasNext()) {
Object obj = (Object)objIt.next();
// some code
}
我的問題是哪一個是內存有效率和迭代速度快?
你說的「爲了得到那個」到底意味着什麼? –
http://stackoverflow.com/questions/2113216/which-is-more-efficient-a-for-each-loop-or-an-iterator –
請在提問之前使用搜索。 Stack Overflow已經提出並回答了很多問題。重複:http://stackoverflow.com/questions/2113216/which-is-more-efficient-a-for-each-loop-or-an-iterator –