Kotlin String Equality


Example

In Kotlin strings are compared with == operator which chect for their structural equality.

val str1 = "Hello, World!"
val str2 = "Hello," + " World!"
println(str1 == str2) // Prints true

Referential equality is checked with === operator.

val str1 = """
    |Hello, World!
    """.trimMargin()

val str2 = """
    #Hello, World!
    """.trimMargin("#")

val str3 = str1

println(str1 == str2) // Prints true
println(str1 === str2) // Prints false
println(str1 === str3) // Prints true