Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 697
yaugenka Avatar asked Feb 12 '20 11:02

yaugenka


1 Answers

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.

like image 91
forpas Avatar answered Oct 06 '22 00:10

forpas