2010-11-18 109 views
1

我在StringTokenizer方法中有一个ifstatement问题,我认为这是由于它是一个char数组,我试图转换它,但它似乎不工作任何帮助将prepresed感谢哈里。java token if语句

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

} 
+0

您至少需要告诉我们“thisToken”的类型是什么。 – DJClayworth 2010-11-18 14:46:17

+1

我对这种想法的新增加了一些代码,但我不知道在哪里我会找出它是什么类型 – 2010-11-18 14:49:18

+0

亲爱的@Ste_T,你知道吗,因为Java是支持异常的类型化语言,如果你不't给我们提供'thisToken'的类型以及执行此代码时发生的异常或错误,我们将完全无法为您提供帮助? – Riduidel 2010-11-18 14:49:49

回答

3

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

你可以尝试

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

如果thisToken实际上恰好是char[]过,那么你可能想使用Arrays.equals(thisToken, password)到阵列的内容进行比较。