Kotlin – Print string to Output

Print string to Output in Kotlin

To print a string or a value to standard consoled output in Kotlin, you can use print() or println() function.

print("Hello World")
println("Hello World")

The basic difference between these two functions is that print() function prints the given value without a trailing new line, whereas println() function prints a trailing new line in addition to the given value.

Examples

Print string using print()

In the following program, we print two string values to output using print() function.

Kotlin Program

fun main(args: Array<String>) {
    print("apple")
    print("banana")
}

Output

Print string to Output in Kotlin using print()

Print string using println()

In the following program, we print two string values to output using println() function.

Kotlin Program

fun main(args: Array<String>) {
    println("apple")
    println("banana")
}

Output

Print string to Output in Kotlin using println()