Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
前任:
val ids = "1,2,3" var result = ids.split(",")
我需要在 Scala 中将字符串数组转换为长数组
val ids = "1,2,3" val result = ids.split(",").map(_.toLong) result: Array[Long] = Array(1, 2, 3)
val ids = "1 ,2, 3" val result = ids.split(',').map(_.trim.toLong)
也适用于数字之间的空格,并且性能稍微好一些,因为它没有隐式地使用正则表达式来分割部分。