What is the equivalent of Java Scanner in Kotlin?

esu picture esu · Feb 27, 2018 · Viewed 7.3k times · Source

What is the equivalent of Java Scanner in Kotlin?

I have used readLine() but I'd like to know whether it's type safe or not?

Answer

UmAnusorn picture UmAnusorn · Mar 20, 2018

You can try something like this

val scan = Scanner(System.`in`)

val n = scan.nextLine().trim().toInt()

Since "in" is a Kotlin keyword