- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Kotlin equivalent of Java's equalsIgnoreCase
Java provides a String method called equalsIgnoreCase() which helps developers to compare two strings on the basis of their content. This comparison is case-insensitive, that is, it ignores whether the strings are in uppercase or lowercase and just compares the string values. In this article, we will see how we can implement the same functionality in Kotlin.
Example – equalsIgnoreCase in Java
The following example demonstrates how equalsIgnoreCase() works in Java.
public class MyClass { public static void main(String args[]){ String s1="TutorialsPoint"; String s2="tutorialspoint"; System.out.println("String 1: " + s1); System.out.println("String 2: " + s2); // Strings match as we ignore the case System.out.println("Strings match? : " + s1.equalsIgnoreCase(s2)); } }
Output
It will produce the following output −
String 1: TutorialsPoint String 2: tutorialspoint Strings match? : true
Example – equalsIgnoreCase in Kotlin
Now, let's check how we can implement the same concept in Kotlin.
fun main(args: Array<String>) { val t1 = "TutorialsPoint.com"; val t2 = "TutorialsPoint"; val t3 = "tutorialspoint"; // false as the strings do not match println("String 1: " + t1) println("String 2: " + t2) println("String 3: " + t3) // comparing t1 and t2 println("Strings 1 and 2 match? : " + t1.equals(t2, ignoreCase = true)); // comparing t2 and t3 // both the strings match as we ignore their case println("Strings 2 and 3 match? : " + t2.equals(t3, ignoreCase = true)); }
Output
It will produce the following output −
String 1: TutorialsPoint.com String 2: TutorialsPoint String 3: tutorialspoint Strings 1 and 2 match? : false Strings 2 and 3 match? : true
- Related Articles
- Equivalent of getClass() for KClass in Kotlin
- Swift "if let" statement equivalent in Kotlin
- What is the equivalent of Java static methods in Kotlin?
- What is the equivalent of Java static final fields in Kotlin?
- What's the Kotlin equivalent of Java's String[]?
- Java String equalsIgnoreCase() method example.
- Difference between equals() vs equalsIgnoreCase() in Java
- How to use equalsIgnoreCase () in Android textview?
- How to use equals() and equalsIgnoreCase() in Java.
- C++ equivalent of instanceof
- Simplified Equivalent Circuit of Transformer
- MongoDB equivalent of WHERE IN(1,2,…)?
- PHP equivalent of friend or internal
- Equivalent Circuit of a Synchronous Motor
- Swift: #warning equivalent

Advertisements