Relational operators let you compare values. Every comparison gives you a Boolean — true or false.
The comparison operators
fun main() {
val x = 5
val y = 10
println("x == y: ${x == y}") // equal to
println("x != y: ${x != y}") // not equal to
println("x < y: ${x < y}") // less than
println("x > y: ${x > y}") // greater than
println("x <= y: ${x <= y}") // less than or equal to
println("x >= y: ${x >= y}") // greater than or equal to
}
Important: == in Kotlin
In Java, == compares object references, not the actual content. In Kotlin, == compares the values (it's like calling .equals() in Java). If you actually want to check reference equality, use ===.
fun main() {
val a = "hello"
val b = "hello"
println(a == b) // true - same content
println(a === b) // probably true due to string pooling, but don't rely on it
}
Most of the time, you'll use == and it'll do exactly what you expect.