equals(String otherString) function to compare strings, not the == operator. This is because the == operator only compares object references , while the String. equals() method compares both String ‘s values i.e. the sequence of characters that make up each String .