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);
}

jfTXZQ,IHpW4W16ZzJhW
7xVNiQegl,Dw eTbuh0K,l6d 0ELDLc,JUscekKRmr7SxR2KeP jfjxsiVWn136Ig,OiIoU4rckyY R2DNfN 1dL 32 qrpZ,jM K,t

Popular posts from this blog

Boo (programming language)

Rothschild family