Trying to get a value from a map only using the beginning of a key. If a have map of <strings,strings> and I know the beginning of the key will be either "aaa", "bbb", or "ccc", is there a way to retrieve that String Value.
Example Map
"aaa_unknownText" -> "hello world"
"bbb_unknown_Text" -> "hello mars"
"ccc_unknown_TEXT" -> "hello jupiter"
Want to get the String Value of "bbb" which is "hello mars"
My thought process was to get the Keys in a list. Then go through list checking each string until I found a match, saving that Key in val foundKey. Then using map.get(foundKey) to get the String Value. New to Kotlin wanted to know if there was a different way, maybe using map.filter option, Thanks!
-Thanks for your response! Took pieces of code and currently have
map.filterkeys { it.startsWith("bbb") }.toList().map{ it.second }[0]
The keys "aaa", "bbb", and "ccc" will only appear once in the map, and guaranteed will appear. Needed the result value as a string so turned it into a list and got index [0]