The right way of comparing String in Java is to either use equals(), equalsIgnoreCase(), or compareTo() method . You should use equals() method to check if two String contains exactly same characters in same order. It returns true if two String are equal or false if unequal.