java.lang.String equalsIgnoreCase()
Description :
This java tutorial shows how to use the equalsIgnoreCase() method of java.lang.String class. This method returns boolean data type which signifies if the String is equal to the parameter String regardless of case. The equalsIgnoreCase() method of String class generally compare two string in terms of their character sequence regardless of case.
Method Syntax :
public boolean equalsIgnoreCase(String anotherString)
Parameter Input :
Data Type | Parameter | Description |
---|---|---|
String | anotherString | this is a String parameter where our String is being compared with |
Method Returns :
This method returns boolean datatype true if one of the following condition has been met regardless of case
- The two characters are the same (as compared by the == operator)
- Applying the method Character.toUpperCase(char) to each character of both the Strings resulting to true on each character
- Applying the method Character.toLowerCase(char) to each character of both the Strings resulting to true on each character
Java Code Example :
This example source code demonstrates the use of equalsIgnoreCase() method of String class. Basically this source code just checks the equality of two strings regardless of character cases.
package com.javatutorialhq.java.tutorial.string; /* * Example source code to check if two string are equal regardless of case */ public class StringEqualsIgnoreCase { public static void main(String[] args) { String ourString = new String("Example String"); // test equality of two strings regardless of case boolean equality = ourString.equalsIgnoreCase("example sTRING"); if(equality){ System.out.println("String is equal"); } else{ System.out.println("String is not equal"); } } }
Sample Output :
Running the equalsIgnoreCase() method example source code of java.lang.String class will give you the following output: