Reputation: 856
I have an Iterator[String] that I want to convert to a String in Scala. I would expect the following to work, but I get no output. What am I doing wrong?
val it = Iterator("a", "number", "of", "words")
val combined = "";
while (it.hasNext){
combined = combined + it.next()
}
println(combined)
Upvotes: 3
Views: 5947
Reputation: 108169
Your code can't even compile, since you're reassigning a val
it.mkString
will do what you're after
Upvotes: 13