20 runnable Kotlin code examples.
Open any Kotlin example to explore the code and run it online. No setup, no signup.Explore practical Kotlin code examples with clear explanations. Open any example to edit and run it online — no setup, no signup.
Kotlin
20How to check for null in KotlinHow to create a static method in KotlinHow to declare and initialize an array in KotlinHow to check a type at runtime in KotlinHow to initialize a list in KotlinHow to check if a lateinit variable is initialized in KotlinHow to define constants in KotlinHow to use a ternary operator in KotlinHow to pass a function as a parameter in KotlinHow to catch multiple exceptions in KotlinHow to use scope functions in KotlinHow to generate a random number in a range in KotlinHow to convert a list to a map in KotlinHow to format a string in KotlinHow to break out of nested loops in KotlinHow to loop with an index in KotlinHow to sort a list of objects by property in KotlinHow to convert a string to an enum in KotlinHow to convert a string to an int in KotlinHow to parse JSON into a data class in Kotlin
Questions & answers
Kotlin examples, explained
Can I run these Kotlin code examples?
Yes. Open any Kotlin example to edit and run its code on the CompileBytes engine without installing anything.
Is this free? Do I need an account?
Every example is free to read, run, edit, and copy. No account is required.
Can I copy these into my own projects?
Yes. These examples are designed to be copied and adapted to your own code.
Where can I run my own code?
Open the Kotlin compiler from the main playground catalog, then paste or write any code you want to run.