0 votes
in Kotlin by
How to compare two strings in Kotlin?

1 Answer

0 votes
by

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.")

    }

}

Related questions

0 votes
0 votes
asked Oct 6, 2021 in Kotlin by Robin
0 votes
asked Oct 6, 2021 in Kotlin by Robin
...