In the following Java code, the if statement conditional does not evaluate to true and its block is skipped.
public void options(String input) { if(input == "x") System.exit(0); }
Input has the right value, so why is the System.exit(0) skipped?
Advertisement
Answer
This is a classic. Don’t use “==” for comparing Strings, use String.equals().