I have some code where I need to add elements to a sequence while iterating over another one. Which way is the 'preferred' or rather the better way of doing that in scala and why?:
Way 1:
val builder = Seq.newBuilder[String]
for(i <- iterator){
builder += i //Everytime I want to add a new element
}
Way 2:
val stringSeq = iterator.foldLeft(Seq[String]()){
case (acc, i) => i +: acc
}