That’s because num
is a Char
, i.e. the resulting values are the ascii value of that char.
This will do the trick:
val txt = "82389235"
val numbers = txt.map { it.toString().toInt() }
The map
could be further simplified:
map(Character::getNumericValue)