How to compare strings case-insensitively in Kotlin? Java equalsIgnoreCase analog
Hello everyone! I just started learning Kotlin after Java and encountered a simple but annoying problem.\n\nIn Java, I used the `equalsIgnoreCase()` method to compare strings. For example, I'm writing an Android app where I need to check the city entered by the user. The user could type "Moscow", "moscow", or "MOSCOW" — all these variants should be considered the same.\n\nIn Java it looked like this:\n```java\nString userInput = "moscow";\nString city = "Moscow";\nif (city.equalsIgnoreCase(userInput)) {\n // City matched\n}\n```\n\nBut in Kotlin I can't find this method! When I try to write `city.equalsIgnoreCase(userInput)`, the compiler gives an error: "Unresolved reference: equalsIgnoreCase". I tried using `==` for comparison, but it's case-sensitive.
No answers yet.
Log in to leave an answer
Blogs
How to Get a Job as a PHP Developer: Tips and Resume
Advanced Date and Time Handling in Rust: chrono and time
Code review in JavaScript: what to check so the code doesn't fall apart
C++ in 2025: A Complete Learning Plan from Beginner to Pro