![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Advertisements