Compare 2 Strings Kotlin

[Solved] Compare 2 Strings Kotlin | Kotlin - Code Explorer | yomemimo.com
Question : kotlin compare string

Answered by : vastemonde

val first = "code"
val second = "code"
val firstCapitalized = "Code"
// with ==
assertTrue { first == second }
assertFalse { first == firstCapitalized }
// with equals
assertTrue { first.equals(second) }
assertFalse { first.equals(firstCapitalized) }
assertTrue { first.equals(firstCapitalized, true) }	// ignores case
// with compareTo
assertTrue { first.compareTo(second) == 0 }
assertTrue { first.compareTo(firstCapitalized) == 32 }
assertTrue { firstCapitalized.compareTo(first) == -32 }
assertTrue { first.compareTo(firstCapitalized, true) == 0 }

Source : https://www.baeldung.com/kotlin/string-comparison | Last Update : Wed, 28 Apr 21

Question : compare 2 strings kotlin

Answered by : defeated-dunlin-r67wbfrlr3lk

string1 == string2 //returns true if they are equal and false if they are not

Source : | Last Update : Thu, 14 Jan 21

Question : kotlin compare strings

Answered by : nooberthannoobcode

val hello = "Hello" val world = "World" // equals() returns true or false val equals = hello.equals(world) // compareTo() will return 0 if true // Any non zero value is false val compare = hello.compareTo(world)

Source : https://beginnersbook.com/2017/12/kotlin-tutorial/ | Last Update : Tue, 03 Nov 20

Answers related to compare 2 strings kotlin

Code Explorer Popular Question For Kotlin