About 95% of time, I prefer comparing strings by using Java String class’ equal methods. It is shown below:
String equal method observes if exactly similar string of characters are present in Java strings, they would be considered as equal.
Quick String comparison could be observed, with equal method, 2 strings wouldn’t be equal as same characters are not present.
String string1 = "foo";