What is the means to convert the following java String[] to a Scala List?
val trimmedList : List[String] = str.split("\\n")).map (_.trim) // Missing some code here, does not compile
For simplicity, use toList
:
val trimmedList: List[String] = str.split("\\n").map(_.trim).toList
For complexity, use breakOut
(which avoids creating an intermediate collection from map
):
import collection.breakOut
val trimmedList: List[String] = str.split("\\n").map(_.trim)(breakOut)