Operators

Arithmetic and comparison work as expected, but Kotlin's == and === split content equality from reference equality — the reverse of what Java does by default.

Arithmetic and comparison

The usual arithmetic operators work as expected, and comparisons return a Boolean:

</> main.kt
fun main() {
    val a = 17
    val b = 5

    println(a + b)
    println(a % b)
    println(a > b)
    println(a.toDouble() / b)
}
Output
22
2
 true
3.4

a / b between two Ints performs integer division and truncates — 17 / 5 is 3, not 3.4. Converting one operand to Double first with .toDouble() forces real division.

Structural equality: == vs ===

This is the operator most likely to trip up someone coming from Java. In Kotlin, == checks structural equality (calls .equals()), while === checks referential equality (are these the exact same object in memory):

</> main.kt
fun main() {
    val a = "hello"
    val b = "hel" + "lo"

    println(a == b)
    println(a === b)
}
Output
true
false

The content is identical, so == is true. But b was built at runtime by concatenation rather than being the same interned string literal, so it's a different object — === is false. This is the opposite default from Java, where plain == on objects compares references and you have to call .equals() explicitly for content.

Note: This flip is deliberate and one of Kotlin's most-cited improvements over Java: the classic Java bug of writing if (str1 == str2) expecting content comparison and getting reference comparison instead simply can't happen in Kotlin — == already does what most people expect.