Q:

How do I swap some characters of a String with values of a HashMap in Kotlin?

Assuming I have a 
val s: String = "14ABC5"

and have a HashMap
val b: HashMap<String,String> = hashMapOf("A" to "10", "B" to "11", "C" to "12", "D" to "13", "E" to "14", "F" to "15" )

How would I change all occurrences of A,B,C with 10, 11, 12 while keeping their order ("1", "4", "10", "11", "12", "5")?
So far I have this 
val result: List<String> = s.toUpperCase().toCharArray().map{ it.toString() }.map{ it -> b.getValue(it)}

which works if ALL characters of the String exist in the HashMap but my String may contain inexistent keys as well. 

A:

You could either use getOrDefault(...), or the Kotlinesque b[it] ?: it.

By the way, if you're using the implicit lambda argument name (it), you can get rid of the it ->.

