Search code examples
kotlinequality

How to compare a value to several other values in one line in Kotlin


Is there a better alternative to this expression in Kotlin: a == b || a == c

I'm looking for something like a == b || c or a.equals(b, c)


Solution

  • I think the simplest way is with the in operator:

    a in listOf(b, c)
    

    you can include as many items as you want inside the list.