本文介紹了迭代器和Listiterator的區別?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
Iterator ite = Set.iterator();
Iterator ite = List.iterator();
ListIterator listite = List.listIterator();
我們可以使用Iterator
來遍歷Set
或List
或Map
.但是ListIterator
只能用來遍歷List
,不能遍歷Set
.為什么?
We can use Iterator
to traverse a Set
or a List
or a Map
. But ListIterator
can only be used to traverse a List
, it can't traverse a Set
. Why?
我知道主要區別在于,使用迭代器我們只能在一個方向上移動,而使用 ListIterator
我們可以雙向移動.還有其他區別嗎?ListIterator
比 Iterator
有什么優勢?
I know that the main difference is that with iterator we can travel in only one direction but with ListIterator
we can travel both directions. Are there any other differences? And any advantages of ListIterator
over Iterator
?
推薦答案
ListIterator
你可以
- 向后迭代
- 隨時獲取迭代器.
- 隨時添加新值.
- 此時設置一個新值.
這篇關于迭代器和Listiterator的區別?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!