matching vector element to string

I am writing a simple Naive Bayesian spam filter.

My problem is when trying to train the filter on a tagged corpus. I have converted the file to a vector with each element corresponding to a word and the first being a tag either spam or ham

if(tokens.firstElement() == "spam")

{

spamCount++;

tokens.removeElementAt(0);

wordCount += tokens.size();

spamMap = DataMap.learn(spamMap, tokens);

}

else if(tokens.firstElement().toString() == "ham")

{

hamCount++;

tokens.removeElementAt(0);

wordCount += tokens.size();

hamMap = DataMap.learn(hamMap, tokens);

}

else { System.out.print("\n" + tokens.firstElement()); }

}

I know that the vector elements hold the right values but the if statements are failing 100%

[819 byte] By [Dark_Phoenixa] at [2007-11-26 18:58:15]
# 1
When comparing Strings, you should generally use the equals() method rather than the == operator.
glevnera at 2007-7-9 20:38:29 > top of Java-index,Java Essentials,Java Programming...
# 2
cheers - works great now. back to the grindstone
Dark_Phoenixa at 2007-7-9 20:38:29 > top of Java-index,Java Essentials,Java Programming...