What are the benefits of the Iterator interface in Java?

后端 未结 16 1928
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 14:35

I just learned about how the Java Collections Framework implements data structures in linked lists. From what I understand, Iterators are a way of traversing th

16条回答
  •  暖寄归人
    2020-12-04 15:21

    Iterators can be used against any sort of collection. They allow you to define an algorithm against a collection of items regardless of the underlying implementation. This means you can process a List, Set, String, File, Array, etc.

    Ten years from now you can change your List implementation to a better implementation and the algorithm will still run seamlessly against it.

提交回复
热议问题