How can I convert the List(1,2,3)
in Scala to a formatted string like "1/2/3"
with the List methods?
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 res1: String = 123 // def mkString(start: String,sep: String,end: String): String scala> List(1,2,3).mkString("@", "/", "@") res2: String = @1/2/3@
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With