I am having a problem with parsings strings; I can't seem to find out why my String Array's values are not equal to what they should be! This may seem weird, so here is a simplified version of the code (The application is much larger, so I just made a small program to explain my point)
public class Test {
public static void main(String[] args) {
String src = "beep zap derp flop";
String delims = "[ ]+";
String[] tokens = src.split(delims);
if (tokens[0] == "beep") {
System.out.println("you said beep!");
} else {
for (int i = 0; i < tokens.length; i++) {
System.err.println("'" + tokens[i] + "'");
}
}
}
}
My output is
'beep'
'zap'
'derp'
'flop'
I know for a fact that tokens[0] is beep, but the Java does not seem to notice. Is there something I am doing wrong?