You can try calling something like toVector
on it so it stores it in a persistent collection, then you can iterate over it as many times as you like.
Iterator
will only let you traverse over the contents once, hence if you want to traverse it more than one time then turn it into a collection. Given that you have an Iterator[String]
, calling something like .toVector
on it will give you a Vector[String]
.