Getting strange output when printing result of a string comparison

You’re missing a set of brackets:

System.out.println("Using == ::" + (s3==s4));

In your version, "Using == ::" + s3 is being compared via == to s4, which isn’t what you want.

In general, + has a higher precedence than ==, which is why "Using == ::" + s3==s4 is being evaluated as ("Using == ::" + s3) == s4.

Leave a Comment