Skip to main content
Browse topics

Read String Data Input in Kotlin

1 min read Updated June 30, 2026
Share

Definition

In Kotlin, readLine() reads a line of input from the standard input stream or screen.

Syntax

kotlin
var variable_name = readLine()

// Kotlin Defintion
fun readLine(): String? (source)

Read String in Kotlin Example Program

kotlin
// Read String in Kotlin example program
// Data Input Kotlin Programs, Basic Kotlin Programs

fun main(args: Array < String > ) {
    
    println("Pleas enter the Name")

    var name = readLine()!!
    println("Name is : $name")
}

Sample Output

plaintext
Pleas enter the Name
GOODMAN
Name is :GOODMAN

How It Works

Here is a step-by-step walkthrough of how the Kotlin program for Read String Data Input in Kotlin runs, line by line. Following the flow of the code makes it clear how each statement contributes to the final result:

  1. fun main(args: Array < String > ) { — defines a function used by the program.
  2. println("Pleas enter the Name") — writes a line of output shown in the sample output.
  3. var name = readLine()!! — reads a value entered by the user.
  4. println("Name is : $name") — writes a line of output shown in the sample output.

After running it, compare your console output with the Sample Output above to confirm the program behaves as expected. Try changing the values and re-running the program to see how the result changes — experimenting with small edits is the fastest way to understand the logic and to remember the Kotlin syntax used in this example.

Frequently Asked Questions

What is Read String Data Input in Kotlin?
In Kotlin, readLine() reads a line of input from the standard input stream or screen.
How do I run this Kotlin example?
Run it in IntelliJ IDEA or Android Studio, or compile from the command line with `kotlinc file.kt -include-runtime -d file.jar` and run `java -jar file.jar`.
How can I practice Read String Data Input?
Copy the example into IntelliJ IDEA or Android Studio, run it, then change the values or add print statements to see how the output changes.

Related tutorials

Search tutorials