Q:

Scala - the return using a for() or foreach() in a list

How I can build a string (not to print it) from the returned value of a foreach or for statement applied in a List? 
Let say, I have this:
val names = List("Bob", "Fred", "Joe", "Julia", "Kim")
val x: String = for (name <- names) name //I don't need this println(name)

These name returned string I am trying to put in a String, connecting them by a space.?!

A:

Use mkString(sep: String) function:
val names = List("Bob", "Fred", "Joe", "Julia", "Kim")
val x = names.mkString(" ")      // "Bob Fred Joe Julia Kim"

