Using 'equalsIgnoreCase( )'

 learnt that equals( ) method compares two string and gives true if and only if the both the words are same and are in same case.

i.e.   "dog".equals("DOG");   -> Will give the output as false (Though the two words are same but dog is in lower case where as DOG is in upper case

But if you want to get the result as true when the two words are same but are of different case we've to use the equalsIgnoreCase( ) method as shown below:

"dog".equalsIgnoreCase("DOG");  -> Will give the output as true even though dog is in lower case and DOG is in upper case.

Lets implement this on Eclipse IDE:

1. Create 'equalsIgnoreCaseDemo' class under any project as shown below:



2. Save and Run the 'equalsIngoreCaseDemo' class
3. Observe that the output is displayed in the console as shown below:



After looking at the output, its very clear that equalsIgnoreCase( ) method ignores the case while comparing two strings.

Download this project:

Click here to download the project containing the class file used in this post (You can download this project and import into Eclipse IDE on your machine)