Java String equalsIgnoreCase Method

The Java equalsIgnoreCase method compares a string with user-specified string to check whether they both represent the same sequence of characters or not. Based on the result, it will return Boolean True or False. Remember, while comparing two strings, this Java qualsIgnoreCase method will ignore the case differences (Case sensitivity).

In this article, we will show how to write Java equalsIgnoreCase method with an example. The syntax of the Java String equalsIgnoreCase in Java Programming language is as shown below.

Java String equalsIgnoreCase Method syntax

The following Java equalsIgnoreCase method accepts the string data as the argument. Next, it performs a case-insensitive comparison on existing one with this new string to check whether they are equal or not.

public boolean equalsIgnoreCase(String another_String); // It will return boolean True or False 

//In order to use in program
String_Object.equalsIgnoreCase(String another_String);
  • String_Object: Please specify the valid one. It will compare against the another_String
  • another_String: Please specify the valid string. It is the one we are going to compare with String_Object.

Java String equalsIgnoreCase Example

Here, we use the equalsIgnoreCase in Java to check whether this string and user-specified one is equal or not.

The first Java String equalsIgnoreCase statement will call the public boolean equals (Object Obj) method to compare the string str1 with str2. From the below screenshot, observe that a is returning False because they are different in Case.

The second statement b will call the equalsIgnorecase method to perform a case-insensitive comparison on string str1 and str2. From the above Java screenshot, see that it is returning TRUE because they both are equal.

For e, we checked for non-equivalent values using the equalsIgnoreCase. Here “Tutorial GateWay” is not at all equals to “Java Program”.

Lastly, we used the System.out.println statements to print the output.

// Java String.equalsIgnoreCase example
package StringFunctions;

public class EqualsIgnoreCaseMethod {
	public static void main(String[] args) {
		String str1 = "Tutorial GateWay";
		String str2 = "TUTORIAL GATEWAY";
		String str3 = new String("TUTORIAL Gateway");
		String str4 = new String("Tutorial GATEWAY");
		String str5 = new String("Java Programming");

		boolean a = str1.equals(str2);
		boolean b = str3.equalsIgnoreCase(str4);
		boolean c = str2.equalsIgnoreCase(str4);
		boolean d = str1.equalsIgnoreCase(str3);
		boolean e = str1.equalsIgnoreCase(str5);
		System.out.println("Does the String Object str1 Equals to str2? = " + a);
		System.out.println("Ignore Case: Does the String Object str1 Equals to str2? = " + b);
		System.out.println("Does the String Object str2 Equals to str4? = " + c);
		System.out.println("Does the String Object str1 Equals to str3? = " + d);
		System.out.println("Does the String Object str1 Equals to str5? = " + e);
Java String equalsIgnoreCase Method 1

Java equalsIgnoreCase Example 2

In this Java program, We are going to ask the user to enter any String. Based on the user entered text, it displays the message.

The first statement will ask the user to enter any word. Then we are going to assign the user entered value to variable str.

Next, we used the Java If Else Statement to compare the user entered one with the String_Object “Tutorial gateway” and check whether they are equal or not.

  • If the statement inside the If is True, System.out.println(“Welcome to”); statement printed.
  • Else System.out.println(“Goodbye to Tutorial Gateway”); statement printed.
package StringFunctions;
import java.util.Scanner;

public class EqualsIgnoreCaseMethodex {
 private static Scanner sc;
 public static void main(String[] args) {
 sc = new Scanner(; 
 String str = new String("Tutorial gateway");
 System.out.println("Please Enter any word: ");
 String str1 = sc.nextLine();
 if (str1.equalsIgnoreCase(str)) {
 System.out.println("Welcome to");
 else {
 System.out.println("Goodbye to Tutorial Gateway");
Please Enter any word: 
Welcome to

Let us enter different word

Please Enter any word: 
Goodbye to Tutorial Gateway