Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
fun main() {
val a = arrayOf(1, 2)
val b = arrayOf(1, 2)
println(a == b)
println(a.contentEquals(b))
}false true
- Expecting
true true: unlike lists, arrays are equal by==only when both names point at one array.aandbare two arrays, soa == bisfalse. - Expecting
contentEqualsto look for one shared array: it compares the arrays element by element, so two arrays holding1, 2are equal.
- What does
println(listOf(1, 2) == listOf(1, 2))print, and why? - Which call prints an array's elements, since
println(a)does not?