Question

I have a problem with an ifstatement in a StringTokenizer method i think it is due to it being a char array, I have tryed to convert it but it seems not to work any help would be aprecheated thanks harry.

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

}
Was it helpful?

Solution

Note that a char[] will never equal a String.

You could try

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

If thisToken actually happens to be a char[] too, then you probably want to use Arrays.equals(thisToken, password) to compare the content of the arrays.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top