Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java if statements

is there something wrong with this if statement i am trying to make a swing login system??? thanks :)

 public void login()
    {
           String username = loginField.getText();
           char[] password = loginPass.getPassword();
           if (username.equals("test") && password.equals("test"))
           {
                    System.out.println("logged in");
           }
    }
like image 483
SteT Avatar asked Jun 19 '26 10:06

SteT


1 Answers

You might want

new String(password).equals("test")

instead. Comparing array to string makes little sense.

like image 158
Nikita Rybak Avatar answered Jun 22 '26 00:06

Nikita Rybak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!