Operadores comparativos no Kotlin

Conceitos

FunçãoExpressãoComando
maiora > ba.compareTo(b) == 1
menora < ba.compareTo(b) == -1
maior ou iguala >= ba.compareTo(b) >= 0
menor ou iguala <= ba.compareTo(b) <= 0
iguala = ba.equals(b) ou a.compareTo(b) == 0
diferentea != b!(a.equals(b))

Exemplos

  val a = 22
  val b = 90
 
  println(a > b)
  println(a.compareTo(b) == 1)
val a = 22
val b = 22
 
println(a >= b)
println(a.compareTo(b) >= 0)
val a = 22
val b = 90
 
println(a < b)
println(a.compareTo(b) == -1)
val a = 22
val b = 22
 
println(a == b)
println(a.compareTo(b) == 0)
val a = 22
val b = a
 
println(a == b)
println(a.equals(b))
val a = 22
val b = a
 
println(a != b)
println(!a.equals(b))