Java equalsIgnoreCase() method
Java equalsIgnoreCase() method
The Java equalsIgnoreCase() method is used to compare two strings for equality, ignoring case differences. This means it checks if two strings are equal, regardless of whether the characters are uppercase or lowercase.
This method compares the two strings based on the contents of the strings irrespective of the case of the characters in the string. If any character is not matched, it returns false otherwise it returns true.
Method signature
public boolean equalsIgnoreCase(String anotherString)
anotherString: The string to be compared with the current string.
Example
Let’s understand the usage of the equalsignoreCase() method using an example:
package com.testingdocs.stringmethods;
public class ExampleProgram {
public static void main(String[] args) {
String str1= "TestingDocs";
String str2= "TESTINGDOCS";
String str3= "TestingDoc";
// equalsIgnoreCase() method demo
System.out.println(str1.equalsIgnoreCase(str2));
System.out.println(str1.equalsIgnoreCase(str3));
}
}
Program Output
The output of the program is shown below:
true
false
Java Tutorials
Java Tutorial on this website:
For more information on Java, visit the official website :