100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Kotlin

Operators in Kotlin

Explore Kotlin's arithmetic, comparison, logical, range, and containment operators, including the == vs === distinction.

BasicsBeginner9 min readJul 8, 2026
Analogies

Introduction

Operators let you perform computations and comparisons on values. Kotlin supports the familiar arithmetic, comparison, and logical operators found in most languages, plus a few Kotlin-specific ones: the range operator (..) for creating ranges, and the in / !in operators for checking membership. One important gotcha for developers coming from Java is how equality works: Kotlin's == checks structural equality by calling equals(), while === checks referential equality (whether two references point to the same object).

🏏

Cricket analogy: Comparing two batsmen's stats with < and > is like arithmetic operators, but asking 'is this the same Virat Kohli' (===) differs from 'does this player have identical stats' (==), which checks content not identity.

Syntax

kotlin
val sum = a + b          // arithmetic
val isEqual = a == b     // structural equality
val isSameRef = a === b  // referential equality
val bothTrue = x && y    // logical AND
val within = 1..10       // range
val contained = 5 in 1..10 // containment check

Explanation

Arithmetic operators (+, -, *, /, %) work as expected on numeric types. Comparison operators (<, >, <=, >=) compare ordered values. Logical operators (&&, ||, !) combine boolean expressions. The key difference from Java is equality: in Java, == on objects compares references, but in Kotlin == is overloaded to call the equals() method, so it compares content (structural equality). To check whether two variables reference the exact same object in memory, use ===. The range operator .. creates a range such as 1..10, which is commonly used with the in and !in operators to test whether a value falls inside or outside that range.

🏏

Cricket analogy: Adding a bowler's wickets across matches uses +, and checking if a batting average is >= 50 uses comparison operators, while '&&' combines 'scored a century && took 5 wickets' as an all-round performance check.

Example

kotlin
fun main() {
    val a = 200
    val b = 200
    println(a == b)   // structural equality
    println(a === b)  // referential equality (may differ for boxed values)

    val score = 75
    println(score in 1..100)   // containment
    println(score !in 1..50)   // negated containment

    val passed = score >= 40 && score <= 100
    println(passed)
}

Output

text
true
true
true
true
true

Key Takeaways

  • Kotlin supports arithmetic (+, -, *, /, %), comparison (<, >, <=, >=), and logical (&&, ||, !) operators.
  • == checks structural equality by invoking equals(), unlike Java where == on objects checks references.
  • === checks referential equality, i.e. whether two variables point to the exact same object.
  • The range operator .. creates a range, e.g. 1..10, often used with for loops or containment checks.
  • in and !in test whether a value is contained (or not) within a range or collection.

Practice what you learned

Was this page helpful?

Topics covered

#Kotlin#KotlinProgrammingStudyNotes#Programming#OperatorsInKotlin#Operators#Syntax#Explanation#Example#StudyNotes#SkillVeris