In Java Strings, the == operator is used to check the reference of both the string objects. Use .equals method instead: str1.equals(str2)