contentEquals

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

(Common source) (JVM source) (JS source) (Native source)

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

Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal. Elements 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 structurally equal if both are null.

If the arrays contain nested arrays, use contentDeepEquals to recursively compare their elements.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val array = arrayOf("apples", "oranges", "lime")

// the same size and equal elements
println(array.contentEquals(arrayOf("apples", "oranges", "lime"))) // true

// different size
println(array.contentEquals(arrayOf("apples", "oranges"))) // false

// the elements at index 1 are not equal
println(array.contentEquals(arrayOf("apples", "lime", "oranges"))) // false
//sampleEnd
}

Parameters

other - the array to compare with this array.

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

Common
JVM
JS
Native
1.4
infix fun ByteArray?.contentEquals(
    other: ByteArray?
): Boolean

(Common source) (JVM source) (JS source) (Native source)
infix fun ShortArray?.contentEquals(
    other: ShortArray?
): Boolean

(Common source) (JVM source) (JS source) (Native source)
infix fun IntArray?.contentEquals(other: IntArray?): Boolean
(Common source) (JVM source) (JS source) (Native source)
infix fun LongArray?.contentEquals(
    other: LongArray?
): Boolean

(Common source) (JVM source) (JS source) (Native source)

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

Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.

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

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val array = intArrayOf(1, 2, 3)

// the same size and equal elements
println(array.contentEquals(intArrayOf(1, 2, 3))) // true

// different size
println(array.contentEquals(intArrayOf(1, 2))) // false

// the elements at index 1 are not equal
println(array.contentEquals(intArrayOf(1, 3, 2))) // false
//sampleEnd
}

Parameters

other - the array to compare with this array.

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

Common
JVM
JS
Native
1.4
infix fun FloatArray?.contentEquals(
    other: FloatArray?
): Boolean

(Common source) (JVM source) (JS source) (Native source)
infix fun DoubleArray?.contentEquals(
    other: DoubleArray?
): Boolean

(Common source) (JVM source) (JS source) (Native source)

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

Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal. Elements are compared for equality using the equals function. This means NaN is equal to itself and -0.0 is not equal to 0.0.

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

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val array = doubleArrayOf(1.0, Double.NaN, 0.0)

// the same size and equal elements, NaN is equal to NaN
println(array.contentEquals(doubleArrayOf(1.0, Double.NaN, 0.0))) // true

// different size
println(array.contentEquals(doubleArrayOf(1.0, Double.NaN))) // false

// the elements at index 2 are not equal, 0.0 is not equal to -0.0
println(array.contentEquals(doubleArrayOf(1.0, Double.NaN, -0.0))) // false

// the elements at index 1 are not equal
println(array.contentEquals(doubleArrayOf(1.0, 0.0, Double.NaN))) // false
//sampleEnd
}

Parameters

other - the array to compare with this array.

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

Common
JVM
JS
Native
1.4
infix fun BooleanArray?.contentEquals(
    other: BooleanArray?
): Boolean

(Common source) (JVM source) (JS source) (Native source)

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

Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.

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

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val array = booleanArrayOf(true, false, true)

// the same size and equal elements
println(array.contentEquals(booleanArrayOf(true, false, true))) // true

// different size
println(array.contentEquals(booleanArrayOf(true, false))) // false

// the elements at index 1 are not equal
println(array.contentEquals(booleanArrayOf(true, true, false))) // false
//sampleEnd
}

Parameters

other - the array to compare with this array.

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

Common
JVM
JS
Native
1.4
infix fun CharArray?.contentEquals(
    other: CharArray?
): Boolean

(Common source) (JVM source) (JS source) (Native source)

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

Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.

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

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val array = charArrayOf('a', 'b', 'c')

// the same size and equal elements
println(array.contentEquals(charArrayOf('a', 'b', 'c'))) // true

// different size
println(array.contentEquals(charArrayOf('a', 'b'))) // false

// the elements at index 1 are not equal
println(array.contentEquals(charArrayOf('a', 'c', 'b'))) // false
//sampleEnd
}

Parameters

other - the array to compare with this array.

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

Common
JVM
JS
Native
1.4
@ExperimentalUnsignedTypes infix fun UIntArray?.contentEquals(
    other: UIntArray?
): Boolean

(source)
@ExperimentalUnsignedTypes infix fun ULongArray?.contentEquals(
    other: ULongArray?
): Boolean

(source)
@ExperimentalUnsignedTypes infix fun UByteArray?.contentEquals(
    other: UByteArray?
): Boolean

(source)
@ExperimentalUnsignedTypes infix fun UShortArray?.contentEquals(
    other: UShortArray?
): Boolean

(source)

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

Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.

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

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val array = intArrayOf(1, 2, 3)

// the same size and equal elements
println(array.contentEquals(intArrayOf(1, 2, 3))) // true

// different size
println(array.contentEquals(intArrayOf(1, 2))) // false

// the elements at index 1 are not equal
println(array.contentEquals(intArrayOf(1, 3, 2))) // false
//sampleEnd
}

Parameters

other - the array to compare with this array.

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

Native
1.1
@DeprecatedSinceKotlin("1.4") infix fun <T> Array<out T>.contentEquals(
    other: Array<out T>
): Boolean

(source)
Deprecated: Use Kotlin compiler 1.4 to avoid deprecation warning.

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

Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal. Elements 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 the arrays contain nested arrays, use contentDeepEquals to recursively compare their elements.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val array = arrayOf("apples", "oranges", "lime")

// the same size and equal elements
println(array.contentEquals(arrayOf("apples", "oranges", "lime"))) // true

// different size
println(array.contentEquals(arrayOf("apples", "oranges"))) // false

// the elements at index 1 are not equal
println(array.contentEquals(arrayOf("apples", "lime", "oranges"))) // false
//sampleEnd
}

Parameters

other - the array to compare with this array.

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

Native
1.1
@DeprecatedSinceKotlin("1.4") infix fun ByteArray.contentEquals(
    other: ByteArray
): Boolean

(source)
Deprecated: Use Kotlin compiler 1.4 to avoid deprecation warning.
@DeprecatedSinceKotlin("1.4") infix fun ShortArray.contentEquals(
    other: ShortArray
): Boolean

(source)
Deprecated: Use Kotlin compiler 1.4 to avoid deprecation warning.
@DeprecatedSinceKotlin("1.4") infix fun IntArray.contentEquals(
    other: IntArray
): Boolean

(source)
Deprecated: Use Kotlin compiler 1.4 to avoid deprecation warning.
@DeprecatedSinceKotlin("1.4") infix fun LongArray.contentEquals(
    other: LongArray
): Boolean

(source)
Deprecated: Use Kotlin compiler 1.4 to avoid deprecation warning.
@DeprecatedSinceKotlin("1.4") @ExperimentalUnsignedTypes infix fun UIntArray.contentEquals(
    other: UIntArray
): Boolean

(source)
Deprecated: Use Kotlin compiler 1.4 to avoid deprecation warning.
@DeprecatedSinceKotlin("1.4") @ExperimentalUnsignedTypes infix fun ULongArray.contentEquals(
    other: ULongArray
): Boolean

(source)
Deprecated: Use Kotlin compiler 1.4 to avoid deprecation warning.
@DeprecatedSinceKotlin("1.4") @ExperimentalUnsignedTypes infix fun UByteArray.contentEquals(
    other: UByteArray
): Boolean

(source)
Deprecated: Use Kotlin compiler 1.4 to avoid deprecation warning.
@DeprecatedSinceKotlin("1.4") @ExperimentalUnsignedTypes infix fun UShortArray.contentEquals(
    other: UShortArray
): Boolean

(source)
Deprecated: Use Kotlin compiler 1.4 to avoid deprecation warning.

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

Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val array = intArrayOf(1, 2, 3)

// the same size and equal elements
println(array.contentEquals(intArrayOf(1, 2, 3))) // true

// different size
println(array.contentEquals(intArrayOf(1, 2))) // false

// the elements at index 1 are not equal
println(array.contentEquals(intArrayOf(1, 3, 2))) // false
//sampleEnd
}

Parameters

other - the array to compare with this array.

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

Native
1.1
@DeprecatedSinceKotlin("1.4") infix fun FloatArray.contentEquals(
    other: FloatArray
): Boolean

(source)
Deprecated: Use Kotlin compiler 1.4 to avoid deprecation warning.
@DeprecatedSinceKotlin("1.4") infix fun DoubleArray.contentEquals(
    other: DoubleArray
): Boolean

(source)
Deprecated: Use Kotlin compiler 1.4 to avoid deprecation warning.

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

Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal. Elements are compared for equality using the equals function. This means NaN is equal to itself and -0.0 is not equal to 0.0.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val array = doubleArrayOf(1.0, Double.NaN, 0.0)

// the same size and equal elements, NaN is equal to NaN
println(array.contentEquals(doubleArrayOf(1.0, Double.NaN, 0.0))) // true

// different size
println(array.contentEquals(doubleArrayOf(1.0, Double.NaN))) // false

// the elements at index 2 are not equal, 0.0 is not equal to -0.0
println(array.contentEquals(doubleArrayOf(1.0, Double.NaN, -0.0))) // false

// the elements at index 1 are not equal
println(array.contentEquals(doubleArrayOf(1.0, 0.0, Double.NaN))) // false
//sampleEnd
}

Parameters

other - the array to compare with this array.

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

Native
1.1
@DeprecatedSinceKotlin("1.4") infix fun BooleanArray.contentEquals(
    other: BooleanArray
): Boolean

(source)
Deprecated: Use Kotlin compiler 1.4 to avoid deprecation warning.

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

Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val array = booleanArrayOf(true, false, true)

// the same size and equal elements
println(array.contentEquals(booleanArrayOf(true, false, true))) // true

// different size
println(array.contentEquals(booleanArrayOf(true, false))) // false

// the elements at index 1 are not equal
println(array.contentEquals(booleanArrayOf(true, true, false))) // false
//sampleEnd
}

Parameters

other - the array to compare with this array.

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

Native
1.1
@DeprecatedSinceKotlin("1.4") infix fun CharArray.contentEquals(
    other: CharArray
): Boolean

(source)
Deprecated: Use Kotlin compiler 1.4 to avoid deprecation warning.

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

Two arrays are considered structurally equal if they have the same size, and elements at corresponding indices are equal.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val array = charArrayOf('a', 'b', 'c')

// the same size and equal elements
println(array.contentEquals(charArrayOf('a', 'b', 'c'))) // true

// different size
println(array.contentEquals(charArrayOf('a', 'b'))) // false

// the elements at index 1 are not equal
println(array.contentEquals(charArrayOf('a', 'c', 'b'))) // false
//sampleEnd
}

Parameters

other - the array to compare with this array.

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