I need to split a string into an array of integers. I tried this:
val string = "1234567"
val numbers = string.split("").map { it.toInt() }
println(numbers.get(1))
but the following Exception is thrown:
Exception in thread "main" java.lang.NumberFormatException:
For input string: "" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:592) at java.lang.Integer.parseInt(Integer.java:615) at net.projecteuler.Problem_008Kt.main(Problem_008.kt:54)
How to convert a string "123456" into array [1,2,3,4,5,6]?