allEqual

Returns true if all elements in the sequence are equal to each other.

Returns true for an empty sequence.

The elements are compared sequentially using structural equality (==), and all elements are considered equal if the first element equals every subsequent element.

For elements of floating-point types (Double, Float), NaN is considered equal to NaN, and -0.0 is considered not equal to 0.0, consistent with Double.equals and Float.equals.

The operation is terminal.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(sequenceOf<String>().allEqual()) // true
println(sequenceOf("apple").allEqual()) // true

println(sequenceOf("apple", "apple", "apple").allEqual()) // true

println(sequenceOf("apple", "apple", "orange").allEqual()) // false 
   //sampleEnd
}