Boolean Array
Make an array of true/false values.
1fun main() {
2 val flags = booleanArrayOf(true, true, false)
3 println(flags.contentToString())
4}
$ kotlinc Main.kt -include-runtime -d Main.jar
$ java -jar Main.jar
[true, true, false]
Every line, explained
fun main() {- Every Kotlin program starts at the main function. When you run the program, Kotlin looks for fun main() and runs everything between its { and } from top to bottom.
val flags = booleanArrayOf(true, true, false)- booleanArrayOf(...) makes an array of true/false values. Just like before, you read items back by index: flags[0] is true, flags[2] is false.
println(flags.contentToString())- Careful: printing an array directly, println(arr), does NOT show its contents in Kotlin! It prints a strange code like [I@1b6d3586 (the exact letters depend on the array's type). arr.contentToString() turns the array into readable text like [1, 2, 3] first, and that is what we print.
}- This closing curly brace } ends the main function. In Kotlin every opening brace { must have a matching closing brace }.