Given Iterator<Element>
, how can we conveniently convert that Iterator
to a List<Element>
, so that we can use List
's operations on it such as get(index)
, add(element)
, etc.
Java – Convert Iterator to List
iteratorjavalist
iteratorjavalist
Given Iterator<Element>
, how can we conveniently convert that Iterator
to a List<Element>
, so that we can use List
's operations on it such as get(index)
, add(element)
, etc.
Best Answer
Better use a library like Guava:
Another Guava example:
or Apache Commons Collections: