【发布时间】:2017-06-12 04:03:44
【问题描述】:
我是编程初学者,我有 Iterator<Iterator<Integer>> it 这样的东西。 it 中的每个迭代器都是一个数字序列。喜欢:
Iterator1 - (1, 2, 3)
Iterator2 - (4, 5, 6)
Iterator3 - (7, 8, 9)
从不同的角度来看,it 是:
Iterator<Iterator<Integer> ((1, 2, 3), (4, 5, 6), (7, 8, 9))
我需要一个方法,它将return Iterator<Integer> (1, 2, 3, 4, 5, 6, 7, 8, 9),比如:
Iterator<Integer> convert(Iterator<Iterator<Integer>> it) {
// How to do it?
}
it 中每个迭代器的数列的大小和值可能不同。
我知道我必须自己尝试,但我什至不明白这里应该发生什么。
【问题讨论】:
-
听起来你在寻找 Guava 的
Iterators.concat。