equals(Object other) function to compare strings, not the == operator . The function checks the actual contents of the string, the == operator checks whether the references to the objects are equal.
Read moreCan you use == to compare strings in Java?
To compare these strings in Java, we need to use the equals() method of the string. You should not use == (equality operator) to compare these strings because they compare the reference of the string , i.e. whether they are the same object or not.
Read moreIs string comparable Java?
Java String compare. We can compare String in Java on the basis of content and reference . It is used in authentication (by equals() method), sorting (by compareTo() method), reference matching (by == operator) etc.
Read moreHow do I compare characters in a string in Java?
You can compare two Strings in Java using the compareTo() method, equals() method or == operator . The compareTo() method compares two strings. The comparison is based on the Unicode value of each character in the strings.
Read more