Reputation: 2450
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?
Upvotes: 14
Views: 23254
Reputation: 81859
Kotlin reuses many existing Java libraries and it's perfectly fine to do so with Scanner
. Otherwise, readLine
simply uses System.in
as you can see here. This might be a simple alternative for you.
Upvotes: 8
Reputation: 11124
You can try something like this
val scan = Scanner(System.`in`)
val n = scan.nextLine().trim().toInt()
Since "in" is a Kotlin keyword
Upvotes: 17