Skip to content

Instantly share code, notes, and snippets.

@magdamiu

magdamiu/KotlinBasics.kt

Last active Nov 17, 2019
Embed
What would you like to do?
Array in Kotlin
var numbers = arrayOf(1, 2, 3, 4, 5)
var colors = arrayOf("red", "blue", "pink", "yellow")
// primitive arrays
val myCharArray = charArrayOf('K', 'O', 'T', 'L', 'I', 'N') // CharArray (corresponds to Java 'char[]')
val myIntArray = intArrayOf(1, 3, 5, 7, 9, 11) // IntArray (corresponds to Java 'int[]')
// Array constructor
val numbersArray = Array(8, { i -> i * 2 }) // 0 2 4 6 8 10 12 14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment