-8
String s1 = "abcdef";
String s3 = new String(s1);
    if(s3 == s1){
     System.out.printf("yes");   
    }else{
            System.out.printf("no");
         }   

Why is not print yes? Who can explain to me?

Alan Yu
  • 1,462
  • 12
  • 21
  • Any basic java string tutorial can explain it to you. – Juned Ahsan Jan 04 '14 at 11:14
  • 3
    When posting questions you should always show the effort that you took to figure out the problem yourself. You asked about some things which are fundamental for the language you are using and are described in various sources. That is why you are getting down votes. Hope that this will help you to become better SO community member – ŁukaszBachman Jan 04 '14 at 11:18
  • This might be helpful :http://stackoverflow.com/a/17489410/1927832 – Suresh Atta Jan 04 '14 at 11:22
  • 1
    Just by going through the Frequently Asked Questions for the Java tag you would have come to the answer. – Marko Topolnik Jan 04 '14 at 11:43

2 Answers2

2

Change s3 == s1 to s3.equals(s1).

The == operator or will check if they're both the same object, rather than what their string value is.

splrs
  • 2,424
  • 2
  • 19
  • 29
0

When you are dealing with Objects, you should use their equals method, not the ==

Check this for further explanation: Java String.equals versus ==

Community
  • 1
  • 1
Nikola Yovchev
  • 9,498
  • 4
  • 46
  • 72