How can I convert the List(1,2,3)
in Scala to a formatted string like "1/2/3"
with the List methods?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Have a look at mkString. In short:
Displays all elements of this list in a string using a separator string (In your case "/")
scala> List(1,2,3).mkString("/")
res0: String = 1/2/3
scala> List(1,2,3).mkString
res0: String = 123
// def mkString(start: String,sep: String,end: String): String
scala> List(1,2,3).mkString("@", "/", "@")
res1: String = @1/2/3@