by Dinesh Thakur

The String class includes several methods that compare strings or substrings within strings. To perform a comparison that ignores case differences, use equalsIgnoreCase(). This method considers lowercase and upper case characters as same while comparing strings. That is, it considers A-Z to be the same as a-z.

Syntax:

boolean equalsIgnoreCase(String str)

 

Here, str is the String object being compared with the invoking String object. It returns true if the strings contain the same characters in the same order, and false otherwise.

import java.io.*;

class StringComparison
{
            public static void main(String args[]) throws IOException
            {
                        BufferedReader dd=new BufferedReader(new InputStreamReader(System.in));
                        String ww;
                        System.out.println("Enter Few Strings or Enter stop to Exit ");
                        do
                        {
                                    ww=dd.readLine();     
                        }while(!ww.equalsIgnoreCase("stop"));
            }
}

String Comparison in Java Example