- 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
Difference between equals() vs equalsIgnoreCase() in Java
Use equals() in Java to check for equality between two strings.
Use equalsIgnoreCase() in Java to check for equality between two strings ignoring the case.
Let’s say the following are our two strings −
String one = "qwerty"; String two = "Qwerty";
Both are equal, but the case is different. Since the method ignores case, both of these strings would be considered equal using equalsIgnoreCase() method.
Here, we are checking the same −
if(one.equalsIgnoreCase(two)) { System.out.println("String one is equal to two (ignoring the case) i.e. one==two"); }else{ System.out.println("String one is not equal to String two (ignoring the case) i.e. one!=two"); }
However, under equals() case, they won’t be considered equal −
if(one.equals(two)) { System.out.println("String one is equal to two i.e. one==two"); }else{ System.out.println("String one is not equal to String two i.e. one!=two"); }
The following is the final example.
Example
public class Demo { public static void main(String[] args) { String one = "qwerty"; String two = "Qwerty"; if(one.equalsIgnoreCase(two)) { System.out.println("String one is equal to two (ignoring the case) i.e. one==two"); }else{ System.out.println("String one is not equal to String two (ignoring the case) i.e. one!=two"); } if(one.equals(two)) { System.out.println("String one is equal to two i.e. one==two"); }else{ System.out.println("String one is not equal to String two i.e. one!=two"); } } }
Output
String one is equal to two (ignoring the case) i.e. one==two String one is not equal to String two i.e. one!=two
- Related Articles
- How to use equals() and equalsIgnoreCase() in Java.
- equals() vs == in Java
- Difference between == and equals() method in Java.
- What is the difference between equals and compareTo in Java?
- What is the difference between equals() method and == operator in java?
- Difference between == and .Equals method in c#
- Java String equalsIgnoreCase() method example.
- Difference between \'__eq__\' VS \'is\' VS \'==\' in Python
- Difference Between Set vs List vs Tuple
- Difference Between Coronavirus vs Flu vs Cold vs Allergies
- Kotlin equivalent of Java's equalsIgnoreCase
- Java String comparison, differences between ==, equals, matches, compareTo().
- What is difference between vs. ?
- Difference between JQuery vs Cypress
- Which equals operator (== vs ===) should be used in JavaScript?

Advertisements