1

我在 StringTokenizer 方法中遇到了 if 语句的问题,我认为这是因为它是一个 char 数组,我尝试对其进行转换,但似乎没有任何帮助,谢谢 harry。

char[] password = loginPass.getPassword();
StringTokenizer st = new StringTokenizer(theText, ",");
if (thisToken.equals(password))
{
      System.out.println("Hi Harry u got the pasword right!!!");

}
4

1 回答 1

3

请注意, achar[]永远不会等于 a String

你可以试试

if (thisToken.equals(new String(password)))

如果thisToken实际上恰好是 a char[],那么您可能想要使用Arrays.equals(thisToken, password)来比较数组的内容。

于 2010-11-18T14:50:10.453 回答