Iterator in Java

前端 未结 3 1081
后悔当初
后悔当初 2021-01-21 12:46

What is Iterator and collections? Does these two have any relations?

// the interface definition
Interface Iterator {
    boolean hasNext();
    Object next();          


        
3条回答
  •  迷失自我
    2021-01-21 13:09

    Technically iterators and collections are not directly related. However Iterators are mostly used together with collections to interate over the objects contained in the collection.

    Iterators are a general and flexible concept that allows to interate objects without depending on the exact implementation of the entity that they iterate over.

提交回复
热议问题