Originally Posted by
BinaryDigit09
Hello,
This is a compile-time constant:
String x = "z";
This is not a compile-time constant:
String userName = myObj.next();
And this compares object reference equality, not object value equality:
userName==x
Even though both variables have a value of "z", they are not the same String object instance. This is the reason why Object.equals() exists. To get the result you expect (print 'true' when userName is "z"), use equals() instead of ==, like this:
System.out.println(userName.equals(x)); // Or x.equals(userName))
Hope that helps!
Thank you very much, it solved the problem, I am very happy for your help, have a good day!!