Interview: Design an iterator for a collection of collections

前端 未结 6 1087
Happy的楠姐
Happy的楠姐 2020-12-29 12:09

Design an iterator for a collection of collections in java. The iterator should hide the nesting, allowing you to iterate all of the elements belonging to all of the collect

6条回答
  •  粉色の甜心
    2020-12-29 12:27

    First, take a look at the implementation of the iterator in java.util.LinkedList

    http://www.docjar.com/html/api/java/util/LinkedList.java.html

    From there your task is easy just implement a single iterator that takes into account the fact that it is iterating over collections.

    Regards.

提交回复
热议问题