Kotlin Playground

A quick and easy way to experiment with Kotlin online without having to install anything. Just change the code and run it!

← Back Backend servers provided by JetBrains

Kotlin to Java

Code targeting the Java platform supports all language features and APIs the JDK provides.

import java.util.Arrays import java.util.stream.Collectors fun main(args: Array<String>) { // How one might do it with plain Java APIs val javaWords = Arrays.asList("hello", "world", "in", "java") System.out.println(javaWords.stream().collect(Collectors.joining(" "))) // How one might do the same with Kotlin APIs val kotlinWords = listOf("hello", "world", "in", "kotlin") println(kotlinWords.joinToString(separator = " ")) }

Kotlin to JavaScript

Code targeting web browsers does not support APIs provided by the JDK unless they've been re-implemented for the JavaScript platform. But any JavaScript API can be called. See here and here for more information.

fun main(args: Array<String>) { alert("Hello World!") console.log("Hello World!") } // Serves sort of like a header declaration. The keyword 'external' tells Kotlin that the // actual implementation is provided by the developer or the platform. In this case it's // Window.alert(). external fun alert(message: String) // Or Window.console. Execute this code snippet and have a look in your web browser's // script console. The type 'dynamic' is only available for the JavaScript platform and // basically disables any type check for this value. external val console: dynamic;