Well, I have a little question that the title already says, how to check a String that receives the Scanner.nextLine() with the if statement.
For example, "msg" is the var that receives the input, I've typed "if (msg === "Hi")" it should print "Hello", but when I put "Hi" in the input box it doesn't prints nothing. I've tried print the msg and it prints "Hi" as I typed.
Is there a way to do that? Below is the code.
In Java, you should use .equals() for string comparisons instead of ==. This is because == checks if both strings refer to the same object, while the .equals() method checks for equality in terms of the string contents.
<, >, <= and >= can only be used with numbers and characters. They cannot be used with Strings, booleans, arrays or other compound types since there's no well-defined notion of order for these objects.
Here is an example of testing objects for equality with equals()