In Java, string comparisons should always be made by calling .equals(). == is for identity comparison, i.e. not just checking if the two strings contains the same characters, but checking if the two strings are one and the same (compare with two people named "Bob". equals() checks if they have the same name while == checks if "Bob" and "Bob" are actually the same person).
The reason why doing a == string comparison sometimes works is because Java optimizes memory usage and tries to reuse one single string for multiple string references if they actually contain the same characters. This trick can be done safely as strings are "immutable", but you can't bet that this optimization will always kick in. For that reason, always compare strings with .equals.