Accepting input from the user

In Kotlin this is the design for accepting input from the user, could someone , line by line, explain what this means ?

readLine()!!.split(’ ') .map(String::toInt)

There are three function invocations here:

  • first readLine function reads a line from the standard input;
    that function can return null in case if the end of the standard input is reached, but if you work with console, you’re sure that it’s not that, so you use !! to assert that the value is not null;
  • then split function invoked on the result of readLine splits the line to a list of strings, using space character as a separator;
  • and then map function takes each element of that list, transforms it with the specified function – String::toInt is a reference to the function String.toInt() – and places the results of transformation to a new list of ints.
1 Like