I'm sure this is a newbie question but I have an initialization function in a class that adds two values to an ArrayList. After the first value is added, it outputs the name of it. When the second is added, it should be outputting the first name followed by the second, but it outputs the second twice. I've already looked through things like this happening elsewhere but they all have to do with static variables or variables outside a loop, so any help is appreciated.
public class CommandManager {
public ArrayList<Command> commands = new ArrayList<Command>();
public void init() {
commands.add(new FlightModes()); //Both FlightModes and Keybinds extend Command
for(Command cm : commands) {
System.out.println(cm.Alias); //Alias is a public string in Command
}
//Outputs "Flightmodes"
commands.add(new Keybinds());
for(Command cm : commands) {
System.out.println(cm.Alias);
}
//Outputs "Keybinds" twice
}
}