0

I am very wondering after executing the below java code.

public class HelloWorld {
    public static void main(String...strings) {
  String s3="abc";
  String s4="abc";
  System.out.println("Result::"+s3==s4);//1
  
  String s1 = "abc";
  String s2 = "abc";
  
  System.out.println(s1 == s2);//2
  
 }
 
 public static void main(String args) {
  System.out.println("From Static Method");
  HelloWorld.main("");
 }

}

Output:

The output is

Result:: false
true

If statement 1 is identical to statement 2, then why statement 1 is false, whereas statement 2 is true

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
jack
  • 112
  • 1
  • 8
  • In your first println you concatenate first the left part of your expression. The correct way could be System.out.println("Result::"+(s3==s4)); – geoandri May 06 '22 at 11:30
  • Hint: `"a"+"b"=="ab"` is `true`. – Pshemo May 06 '22 at 11:30
  • Hint 2: There is no `Result::` part in your output (see again [image you ware trying to include](https://i.stack.imgur.com/5PuxF.png)) – Pshemo May 06 '22 at 13:01

0 Answers0