What is the equivalent of a Java scanner in Kotlin?

What is the Java equivalent Scannerin Kotlin?

I used readLine(), but I would like to know if it is type safe or not?

+4
source share
2 answers

You can try something like this

val scan = Scanner(System.`in`)

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

Since "in" is the Kotlin keyword

+1
source

Kotlin reuses many existing Java libraries, and this is great for Scanner. Otherwise, it readLinesimply uses System.in, as you can see here , which may be a simple alternative for you.

+1
source

Source: https://habr.com/ru/post/1694169/


All Articles