将以下java String []转换为Scala列表的方法是什么?
val trimmedList : List[String] = str.split("\\n")).map (_.trim) // Missing some code here, does not compile
Run Code Online (Sandbox Code Playgroud)
dhg*_*dhg 20
为简单起见,请使用toList:
val trimmedList: List[String] = str.split("\\n").map(_.trim).toList
Run Code Online (Sandbox Code Playgroud)
对于复杂性,使用breakOut(避免从中创建中间集合map):
import collection.breakOut
val trimmedList: List[String] = str.split("\\n").map(_.trim)(breakOut)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20127 次 |
| 最近记录: |