The following is a collection of basic syntax elements with examples.You’ll find detailed descriptions of each topic at the end of each section
Package definition and imports
Package specification should be at the top of the file
package my.demo
import kotlin.text.*
Program entry point
An entry point of a Kotlin application is the main
function:
fun main() {
println("Hello world!")
}
Another form of main
accepts a variable number of String
arguments:
fun main(args: Array<String>) {
println(args.contentToString())
}
Print to the standard output
print("Hello ")
print("world!")
println
prints its arguments and adds a line break, so that the next thing you print appears on the next line:
println("Hello world!")
println(42)