Comparing Text Isn't Working in Java [duplicate]

Multi tool use
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.





Don't use "==" to compare strings. Instead use the equals(...) method.
– camickr
Jul 1 at 18:16


equals(...)




1 Answer
1



Strings are always compared by equals().


equals()


if(("test").equals(passwordBox.getText())) {
passwordBox.setVisible(false);
}

Lz2sFJPoUE2Rg8z,yD78WSS6x5Y 5nZCD7je5AYZ3nJN25 JHIdv
B,1,FI3 L

Popular posts from this blog

Rothschild family

Cinema of Italy