Compares string in Kotlin are possible in the following ways:
Using “==” operator:
You can use ah operator for comparison of two string. In Kotlin == operator is used.
Using compareTo() extension function
Syntax of compareTo() function is given below :
fun String.compareTo(
other: String,
ignoreCase: Boolean = false
): Int
Another code example
fun main(args: <a class="wpil_keyword_link" title="Array" href="https://career.guru99.com/top-50-array-interview-questions-answers/" data-wpil-keyword-link="linked">Array</a> & lt; String & gt;) {
val x: String = "Kotlin is simple"
val y: String = "Kotlin language is" + " easy"
if (x == y) {
println(" x and y are similar.")
} else {
println(" x and y are not similar.")
}
}