Comparing Text Isn't Working in Java [duplicate]

Multi tool use
Comparing Text Isn't Working in Java [duplicate]
This question already has an answer here:
So, I'm trying to do something really simple, and that's check if a password equals something in my SWT application. So, my code was this:
if (passwordBox.getText() == "test") {
passwordBox.setVisible(false);
}
However, in my application, which uses text fields marked as passwords (with that variable), it will not fire that when I click a button. I already have button handling working, since I have an else
statement that fires, but this will not fire when the password box obviously equals "test". What's wrong here?
else
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
equals(...)
1 Answer
1
Strings are always compared by equals()
.
equals()
if(("test").equals(passwordBox.getText())) {
passwordBox.setVisible(false);
}
Don't use "==" to compare strings. Instead use the
equals(...)
method.– camickr
Jul 1 at 18:16