I have a query string in this form:
val query = "key1=val1&key2=val2&key3=val3
I want to create a map with the specified key / value pairs. So far I am doing it like this:
//creating an iterator with 2 values in each group. Each index consists of a key/value pair
val pairs = query.split("&|=").grouped(2)
//inserting the key/value pairs into a map
val map = pairs.map { case Array(k, v) => k -> v }.toMap
Is there a problem with this like me? If so, is there some kind of library that I could use for this?
source
share