18
What is the equivalent of the method String.equalsIgnoreCase()
of Java in Kotlin?
18
What is the equivalent of the method String.equalsIgnoreCase()
of Java in Kotlin?
15
To perform this comparison in Kotlin, pass the "ignoreCase" parameter in the equals function. Below is an example:
val texto1 = "testando";
val texto2 = "TESTANDO";
var resultado = texto1.equals(texto2, ignoreCase = true);
println(resultado);
8
The methods that make sense to have this option, and not only the equals()
do so through a parameter indicating box ignorance (ignore case). See the documentation of equals()
. See also the documentation of String
of Kotlin. Note that most methods have this parameter.
At this point I don’t know if I like Kotlin’s decision since Boolean parameters are usually accepted more or less universally as poor engineering. If you don’t have a very good reason for this choice I think it was a mistake. If you have a good reason it should be very well documented, which I didn’t find. And I love the language.
fun main(args: Array<String>) {
println("Texto Em Caixa".equals("texto em caixa", ignoreCase = true));
println("Texto Em Caixa".equals("texto em caixa", ignoreCase = false));
}
Behold working in the ideone. Andin the repl it.. Also put on the Github for future reference.
Browser other questions tagged string kotlin
You are not signed in. Login or sign up in order to post.