Kotlin Syntax References

Kotlin syntax quick reference: val/var, null safety, data classes, when and collections, from the official Kotlin docs. Every item below is clearly marked as a shortcut, command, or syntax reference.

Most Useful Kotlin Syntax References

KotlinSyntax

Main Function

Code example
fun main() { }

The entry point of a Kotlin program.

Learn More
KotlinSyntax

Print Output

Code example
println("Hello")

Prints a line.

Learn More
KotlinSyntax

Val and Var

Code example
val name = "Ada" var count = 0

val is read-only, var can change.

Learn More
KotlinSyntax

String Template

Code example
"Hi $name, total ${a + b}"

Inserts values into a string.

Learn More
KotlinSyntax

Define a Function

Code example
fun add(a: Int, b: Int): Int = a + b

Defines a function.

Learn More
KotlinSyntax

When Expression

Code example
when (n) { 1 -> "one" else -> "other" }

Matches a value against cases.

Learn More
KotlinSyntax

For Loop over a Range

Code example
for (i in 1..10) { }

Loops over a range.

Learn More
KotlinSyntax

Create a List

Code example
val nums = listOf(1, 2, 3) val items = mutableListOf<String>()

Creates read-only or mutable lists.

Learn More

More Kotlin Syntax References

Frequently Asked Questions

What does this Kotlin syntax reference cover?

It covers 20 common Kotlin patterns and examples, including Main Function, Print Output, Val and Var, String Template, Define a Function.

Can I copy the Kotlin examples?

Yes. Each reference page includes a copyable code example.

What affects these Kotlin examples?

Check the linked documentation for language or runtime version requirements. Libraries, file paths, terminal quoting and environment settings can differ across systems; no blanket platform compatibility is implied.