Search code examples
javainputkotlinjava.util.scanner

What is the equivalent of Java Scanner in Kotlin?


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?


Solution

  • You can try something like this

    val scan = Scanner(System.`in`)
    
    val n = scan.nextLine().trim().toInt()
    

    Since "in" is a Kotlin keyword