I'm trying to identify an object based on user input and have no idea why it's not working...
userInput is just a scanner, and allGames is an arraylist of a bunch of 'Game' classes with IDs like S01, S02 etc.
Game gameToChange = null;
for (Game g : allGames){
System.out.println(g.getId());
}
String gameInput = userInput.nextLine();
System.out.println(gameInput);
for (Game g : allGames){
if (gameInput == g.getId()){
System.out.println("Found it");
gameToChange =g;
}
}
The Game class:
public abstract class Game {
private String identifier;
public Game(String id){
identifier = id;
}
public String getId(){
return this.identifier;
}
}
I have the printout for "found it" just so I can check when it's working...but no matter when I enter the correct string, one that matches one which is already printed out, it never equals it.