String equals and equalsIgnoreCase

String equals and equalsIgnoreCase are used for comparing 2 Strings in java.Both these methods works exactly similar except for equalsIgnoreCase compares String ignoring case consideration.
We have 2 String as defined below

Now using str1.equals(str2) will result as “false
But using str1.equalsIgnoreCase(str2) will give us the output as “true

Complete Example of String equals and equalsIgnoreCase



Please Note:
Both these methods can throw a NullPointerException if the String on which you are using these methods is NULL. So before performing any operation on String please check if the String is not null.
If one of the 2 Strings that you are going to compare is Static, then you should use the Static String to compare other String.
If str1 is a static String and str2 is going to be dynamic, then you should use
str1.equals(str2) to avoid NullPointer exception.


1. String equals – API
2. String equalsIgnoreCase- API