- 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
Java Program to check for equality between two strings ignoring the case
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 = "rocky"; String two = "Rocky";
Both are equal, but the case is different. Since the method ignore case, both of these strings would be considered equal.
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"); }
The following is the complete example.
Example
public class Demo { public static void main(String[] args) { String one = "rocky"; String two = "Rocky"; 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"); } } }
Output
String one is equal to two (ignoring the case) i.e. one==two
- Related Articles
- Golang Program to compare two strings by ignoring case
- Python Program to compare two strings by ignoring case
- Java Program to compare strings for equality
- Check if two strings are equal while ignoring case in Arduino
- Check two ArrayList for equality in Java
- Check two HashMap for equality in Java
- Check two numbers for equality in Java
- Check two float arrays for equality in Java
- Java Program to Check if two strings are anagram
- How to check String for equality under Unicode case folding in Golang?
- Method to check if a String contains a sub string ignoring case in Java
- How to compare two ArrayList for equality in Java?
- Java Program to check whether two Strings are an anagram or not.
- How to compare two strings without case sensitive in Java
- Java Program to Compare Two Strings

Advertisements