If you want case-sensitive comparison to use equals() , otherwise you can use equalsIgnoreCase() .
String s1 = "a"; String s2 = "A"; s1.equals(s2); // false if(!s1.equals(s2)){ // do something } s1.equalsIgnoreCase(s2); // true
Another way to compare strings, which is useful for some cases (e.g. sorting), is to use compareTo , which returns 0 if the strings are equal, > 0 if s1> s2 and < 0 otherwise
if(s1.compareTo(s2) != 0){ // not equal }
There is also compareToIgnoreCase
source share