fun main() {
// Welcome to the Kotlin playground!
// Click the green Run button below to execute.
data class User(val name: String, val role: String)
val team = listOf(
User("Ada Lovelace", "admin"),
User("Grace Hopper", "member")
)
val admins = team.filter { it.role == "admin" }
println("Team size: ${team.size}")
println("Admins: ${admins.map { it.name }}")
// Null safety
val maybeName: String? = team.firstOrNull { it.role == "owner" }?.name
println("Owner: ${maybeName ?: "none"}")
}
Editable in place · Real compilation on JetBrains' servers · Same backend as the official Kotlin docs
Try these examples
Each card below is its own live, runnable Kotlin snippet — click Run on any of them.
data class Point(val x: Int, val y: Int) {
operator fun plus(other: Point) = Point(x + other.x, y + other.y)
}
fun main() {
val a = Point(1, 2)
val b = Point(3, 4)
val (x, y) = a + b
println("Sum: ($x, $y)")
println("Auto toString(): ${a + b}")
}
sealed class Shape {
class Circle(val radius: Double) : Shape()
class Rectangle(val width: Double, val height: Double) : Shape()
}
fun area(shape: Shape): Double = when (shape) {
is Shape.Circle -> Math.PI * shape.radius * shape.radius
is Shape.Rectangle -> shape.width * shape.height
// No 'else' needed — the compiler knows these are the only cases
}
fun main() {
val shapes = listOf(Shape.Circle(3.0), Shape.Rectangle(4.0, 5.0))
shapes.forEach { println("Area: %.2f".format(area(it))) }
}
import kotlinx.coroutines.*
suspend fun fetchUser(id: Int): String {
delay(100) // simulate network latency
return "User#$id"
}
fun main() = runBlocking {
val a = async { fetchUser(1) }
val b = async { fetchUser(2) }
println("Loaded: ${a.await()} and ${b.await()}")
}
fun String.isPalindrome(): Boolean {
val cleaned = this.lowercase().filter { it.isLetterOrDigit() }
return cleaned == cleaned.reversed()
}
fun main() {
val words = listOf("racecar", "kotlin", "A man a plan a canal Panama")
words.forEach { println("\"$it\" -> ${it.isPalindrome()}") }
}
How this works
Unlike the SQL, Python, JavaScript, and TypeScript playgrounds on this site — which run entirely inside your browser via WebAssembly or a JavaScript sandbox — Kotlin has no practical way to compile and run client-side. Kotlin's compiler targets the JVM (and JS/Native backends), and there's no browser-based Kotlin compiler comparable to Pyodide for Python.
So this page embeds the official Kotlin Playground widget, maintained by JetBrains (the creators of Kotlin). When you press Run, your code is sent to JetBrains' own compile servers, compiled for real, executed, and the actual output streams back — the same infrastructure that powers the runnable examples on kotlinlang.org itself. It's genuinely live execution; it just happens on JetBrains' servers rather than in your browser tab.
What to try next
- Kotlin language reference — 30 topic pages, from basics to coroutines and multiplatform
- Kotlin snippets — copy-ready idiomatic patterns
- Learn Kotlin — structured lessons
- Official Kotlin Playground (full page) — for multi-file projects and more target platforms