Home > database >  Confused by 'eq' in Kotlin
Confused by 'eq' in Kotlin

Time:05-10

What does 'eq' means in the following code? I have been learning Kotlin and it confused me!

fun main() {
val intSet = setOf(1, 1, 2, 3, 9, 9, 4)
// No duplicates:
intSet eq setOf(1, 2, 3, 4, 9)
// Element order is unimportant:
setOf(1, 2) eq setOf(2, 1)
}

CodePudding user response:

Presumably, eq is the operator for set equality. It checks if both sets contain the same elements.

I tried your code on the Kotlin playground and it gave me the error: Unresolved reference: eq. To make it work, you would define eq as an enter image description here

Exemple with different order and not only duplicates:

enter image description here

more info here: https://stepik.org/lesson/104333/step/1?unit=78893

  • Related