I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug.
Is == bad? When should it and should it not be used? What's the difference?
The method equals() is more intuitive and compares the content of both variables, whereas depending on how you have declared the types to be compared, the resulted evaluation '==' could not berhave as expected; In short, always prefer using built in methods rather than operators in oriented programming languages when the resourse is available.
It's suggested to review a Java reference or tutorial in this regard, e.g. the Complete Java Reference issued by Oracle Press. It explains
equals( ) Versus ==
It is important to understand that the equals( ) method and the == operator perform two different operations. As just explained, the equals( ) method compares the characters inside a String object. The == operator compares two object references to see whether they refer to the same instance. The following program shows how two different String objects can contain the same characters, but references to these objects will not compare as equal:
The variable s1 refers to the String instance created by “Hello”. The object referred to by s2 is created with s1 as an initializer. Thus, the contents of the two String objects are identical, but they are distinct objects. This means that s1 and s2 do not refer to the same objects and are, therefore, not ==, as is shown here by the output of the preceding example: