contentDeepEquals

Common
JS
Native
1.1
infix fun <T> Array<out T>.contentDeepEquals(
    other: Array<out T>
): Boolean

(Common source) (JS source) (Native source)
JVM
1.1
@JvmName("contentDeepEqualsInline") infix fun <T> Array<out T>.contentDeepEquals(
    other: Array<out T>
): Boolean

(source)

Checks if the two specified arrays are deeply equal to one another.

Two arrays are considered deeply equal if they have the same size, and elements at corresponding indices are deeply equal. That is, if two corresponding elements are nested arrays, they are also compared deeply. Elements of other types are compared for equality using the equals function. For floating point numbers, this means NaN is equal to itself and -0.0 is not equal to 0.0.

If any of the arrays contain themselves at any nesting level, the behavior is undefined.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val identityMatrix = arrayOf(
    intArrayOf(1, 0),
    intArrayOf(0, 1)
)
val reflectionMatrix = arrayOf(
    intArrayOf(1, 0),
    intArrayOf(0, -1)
)

// the elements at index [1][1] are not equal
println(identityMatrix.contentDeepEquals(reflectionMatrix)) // false

reflectionMatrix[1][1] = 1
println(identityMatrix.contentDeepEquals(reflectionMatrix)) // true
//sampleEnd
}

Parameters

other - the array to compare deeply with this array.

Return true if the two arrays are deeply equal, false otherwise.

Common
JS
Native
1.4
infix fun <T> Array<out T>?.contentDeepEquals(
    other: Array<out T>?
): Boolean

(Common source) (JS source) (Native source)
JVM
1.4
@JvmName("contentDeepEqualsNullable") infix fun <T> Array<out T>?.contentDeepEquals(
    other: Array<out T>?
): Boolean

(source)

Checks if the two specified arrays are deeply equal to one another.

Two arrays are considered deeply equal if they have the same size, and elements at corresponding indices are deeply equal. That is, if two corresponding elements are nested arrays, they are also compared deeply. Elements of other types are compared for equality using the equals function. For floating point numbers, this means NaN is equal to itself and -0.0 is not equal to 0.0.

The arrays are also considered deeply equal if both are null.

If any of the arrays contain themselves at any nesting level, the behavior is undefined.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val identityMatrix = arrayOf(
    intArrayOf(1, 0),
    intArrayOf(0, 1)
)
val reflectionMatrix = arrayOf(
    intArrayOf(1, 0),
    intArrayOf(0, -1)
)

// the elements at index [1][1] are not equal
println(identityMatrix.contentDeepEquals(reflectionMatrix)) // false

reflectionMatrix[1][1] = 1
println(identityMatrix.contentDeepEquals(reflectionMatrix)) // true
//sampleEnd
}

Parameters

other - the array to compare deeply with this array.

Return true if the two arrays are deeply equal, false otherwise.