Weird maybe silly problem with String Tokenizer

Hi, i'm new to this forum but i'm a bit stuck a piece of code. It's part of a simple upd server. I can't get it to match the second part of the cSentence String. If someone could give me tip it would be much appreciated.

TIA

L.

...

String cSentence = new String(receivePacket.getData());

// TEST!!!!

System.out.println(cSentence + "."); // E.g. "Login 48123"

StringTokenizer st = new StringTokenizer(cSentence);

String request = new String(st.nextToken());

if ((st.countTokens() >= 1) && request.equals("Login")) {

String a = st.nextToken();

// TEST!!!!

System.out.println(a + ".");

System.out.println(password + "."); // These two seem to print the same result. E.g. "48123"

if (a.equals(password)) {.....} // But this fails. But why?

....

[852 byte] By [luisc7a] at [2007-11-27 3:53:56]
# 1
Perhaps the "password" variable refers to an object whose type is not String, but whose toString() method returns that string "48123". A String's equals() method will always return false for an object that isn't a String.
DrClapa at 2007-7-12 8:58:01 > top of Java-index,Java Essentials,Java Programming...
# 2
They are both strings but thanks.L
luisc7a at 2007-7-12 8:58:01 > top of Java-index,Java Essentials,Java Programming...
# 3

First recomendation.

You are using a StringTokenizer setting the String on the constructor but are not putting any separation criteria. Maybe you should call this:

st.nextToken (" "); instead of nextToken ()

now on you TESTs I guess you may be watching bab, maybe there is a blank space and you dont notice it.

put an else after the if and check again both Strings. Maybe you could want to use compareTo instead of equals to see if something is different

MelGohana at 2007-7-12 8:58:01 > top of Java-index,Java Essentials,Java Programming...
# 4
Hi, I've tryed using st.nextToken(" ") instead of st.nextToken() and (a.compareTo(password) == 0) instead of (a.equals(password)) but it still doesn't work. These two strings should be the same i really don't know what is going on.L
luisc7a at 2007-7-12 8:58:01 > top of Java-index,Java Essentials,Java Programming...
# 5

ok then do this.

put the compareTo out of the if. I mean

int dif=a.compareTo (password);

if (dif==0) {

. //your code

} else {

. System.out.println (": "+dif);

}

if you go to the else then a non zero number will appear this means that your two Strings are not the equals. First try this and tell me the results.

MelGohana at 2007-7-12 8:58:01 > top of Java-index,Java Essentials,Java Programming...
# 6
Could there be blank space in either string? Try playing around with String.trim() and String.length().
OleVVa at 2007-7-12 8:58:01 > top of Java-index,Java Essentials,Java Programming...