java - Why System.out.println("hey s1==s2:"+s1==s2); prints "false" as the output instead of printing "hey s1==s2:false" -


); String s2 = new string ("Shan"); String s3 = "grace"; String s4 = "grace"; System.out.println ("he s1 == s2:" + s1 == s2); Println ("S3 == S4:" + S3 == S4); System.out.println ("s1.equals (s2):" + s1.equals (s2)); System.out.println ("s3.equals (s4):" + s3.equals (s4)); System.out.println ("s1 == s3:" + s1 == s3); System.out.println ("s1.equals (s3):" + s1.equals (s3)); System.out.println ("he s1 == s2:" + true);

Output:

  false false s1.equals (s2): true s3.equals (s4): true wrong s1.equals (s3): true Hey s1 == s2: true  

Why line # 5 results as "O s1 == s2: false" instead of just "false" as output?

  line 5: System.out.println ("he s1 == s2:" + S1 == s2);  

Before resolving operator's priority "s1 = s2:" + s1 before and then s2 For those who go false.

Give it the highest priority to solve it right. Parenthesis is the top priority.

  System.out.println ("he s1 == s2:" + (s1 == s2));  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -