How to return specific option type by splitting a string using scala? -
i have following string , want split using scala
"myinfo": "name-name;model-model;number-10"
i want split value of myinfo string such can access myname , value seperately. e.g. myname:name, model:r210 etc
i using following code split string.
val data = (mainstring \ "myinfo").as[string].split("\\;").map(_.split("\\-").tolist) .collect { case key :: value :: _ => key -> value }.tomap
it gives me desired result.
i using
data.get("name"),data.get("model"),data.get("number")
to access list. gives me results in string type. while want result of data.get("number") in integer format.
how result of 'number' in integer format?
data.get("number").map(_.toint)
will return option[int]
Comments
Post a Comment