Answers for "kotlin string equality"

1

kotlin compare string

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 }
Posted by: Guest on April-21-2021
0

kotlin compare strings

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)
Posted by: Guest on October-27-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language