java tutorial - Java Strings equalsIgnoreCase() method - java programming - learn java - java basics - java for beginners



 Java - The equalsIgnoreCase() method

Learn java - java tutorial - Java - The equalsIgnoreCase() method - java examples - java programs

Description

  • Java Strings equalsIgnoreCase() method— compares this string to another string, ignoring the case.
  • Two lines are considered equal if they have the same length and the corresponding characters for the two strings are equal, ignoring the case of letters.

Syntax

The syntax of the method is:

public boolean equalsIgnoreCase(String anotherString)
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • anotherString is a string for comparison with the specified string.

Return value

  • In Java, equalsIgnoreCase () returns true if the argument is not null and the lines are equal, ignoring the case of letters; otherwise false.

Sample Code

public class Test {

   public static void main(String args[]) {
      String Str1 = "Welcome to wikitechy.com";
      String Str2 = Str1;
      String Str3 = new String("A site for learning programming");
      String Str4 = new String("WELCOME TO WIKITECHY.COM");
      boolean retVal;

      retVal = Str1.equalsIgnoreCase(Str2);
      System.out.println("Is Str1 equal to Str2? Answer:" + retVal );

      retVal = Str1.equalsIgnoreCase(Str3);
      System.out.println("Is Str1 equal to Str3? Answer:" + retVal );
      
      retVal = Str1.equalsIgnoreCase(Str4);
      System.out.println("Is Str1 equal to Str4? Answer:" + retVal );
   }
}
click below button to copy the code. By - java tutorial - team

Output :

Is Str1 equal to Str2? Answer:true
Is Str1 equal to Str3? Answer:false
Is Str1 equal to Str4? Answer:true

Related Searches to Java Strings equalsIgnoreCase() method