shayon shayon - 1 year ago 81
Scala Question

Scala : Print List of List into a file : each nested list is a new line

Pretty New to Scala.
Trying this

val ListNew=List(List("this", "is", "it?"), List("yeah", "what", "else", "do","you","expect"))

into a File / Screen , like this:

this is it? \n
yeah what else do you expect

I did manage it with the following code

var ctr =0 ;> for(rec <-k ) {ctr=ctr+1 ;if (ctr == k.length){print(rec +"\n " );ctr =0; } else {print(rec+" ")} })

But I dont want counters : Is there a way to get a print "\n" before two foreach .I tried Iterators , could not get them right

Answer Source
println(" ")).mkString("\n"))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download