user3663882 user3663882 - 3 months ago 16
Scala Question

Transform map to key=value pairs

I have a

map: Map[AnyRef, AnyRef]
. What is the best way to map it in the following string

"key1=value1 key2=value2 ..."


In Java that's easy. I would just use it

map.entrySet()
.stream()
.map(e -> e.getKey().toString() + "=" + e.getValue().toString())
.collect(joining(" "))


But how to do that in Scala?

Answer
map.map( case (a, b) -> a.toString + "=" + b.toString).mkString(" ")