3

How to convert, Array of Map to a single Map

Array(Map(k1 -> v1), Map(k2 -> v2),  Map(k3 -> v3), Map(k4 -> v4))

to a single Map object

Map(k1 -> v1, k2 -> v2, k3 -> v3, k4 -> v4)

2 Answers 2

9
val arr = Array(Map("k1" -> "v1"), Map("k2" -> "v2"), Map("k3" -> "v3"), Map("k4" -> "v4"))
arr.flatten.toMap
Sign up to request clarification or add additional context in comments.

Comments

0
val m = arr.flatMap(identity).toMap

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.