当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Comparing JTextField value to multiple arrays

问题描述:

This question already has an answer here:

  • How do I compare strings in Java?

    23 answers

网友答案:

In java Strings are compared with equals and not ==. The reason is, strings are objects and not primitives. See Java == vs equals() confusion for more information about == and equals()

So the if expression is wrong:

username.getText().equals(dbUser.get(i)) && password.getText().equals( dbPassword.get(i))
网友答案:

If you want to compare Strings use equals method, == will compare addresses

So change

if(username.getText() == dbUser.get(i) && password.getText()== dbPassword.get(i))

to

if(username.getText().equals(dbUser.get(i)) && password.getText().equals(dbPassword.get(i)))
分享给朋友:
您可能感兴趣的文章:
随机阅读: