To check if two strings are equal in Kotlin, you can use the ==
operator or the equals()
method.
In this example,
str1
and str2
with the same value "Hello"
.str1 == str2
, which will return true
if they are equal and false
otherwise.fun main() {
val str1 = "Hello"
val str2 = "Hello"
val result = str1 == str2
println("Are strings equal? $result")
}
Are strings equal? true
In this example,
str1
and str2
with the same value "Hello"
.equals()
method to check if str1
equals str2
, which will return true
if they are equal and false
otherwise.fun main() {
val str1 = "Hello"
val str2 = "Hello"
val result = str1.equals(str2)
println("Are strings equal? $result")
}
Are strings equal? true
In this tutorial, we learned How to check if Two Strings are Equal in Kotlin language with well detailed examples.