I have an else-if
loop that compares a variable to a String
letter, but it does not seem to detect any matches. My code is as follows:
public static void useMove(String move){
System.out.println(move);
System.out.println(move.getClass().getName());
if(move == "N"){
GLObject.MOVE('N');
}
else if(move == "E"){
GLObject.MOVE('E');
}
else if(move == "S"){
System.out.println("GOT HERE");
GLObject.MOVE('S');
}
else if(move == "W"){
GLObject.MOVE('W');
}
else if(move == "HELLO"){
GLObject.HELLO();
}
else if(move == "PICKUP"){
GLObject.PICKUP();
}
else if(move == "LOOK"){
GLObject.LOOK();
}
else if(move == "QUIT"){
GLObject.QUIT();
}
}
If I enter the value of move as the String "S" it does not detect that move is equal to "S". So the output I get is:
S
java.lang.String
Can anyone advise as to what the problem is?
Thanks very much.