Scala - convert map key value to string
2 answers
I believe this mkString
is the correct way to concatenate delimited strings. You can apply it to tuples as well for consistency using productIterator
:
Map("ss"-> "yy", "aa"-> "bb")
.map(_.productIterator.mkString(":"))
.mkString("|")
Note that it productIterator
loses type information. In the case of strings that won't do much harm, but might make a difference in other situations.
+8
source to share