Seltsame Ausgabe beim Drucken des Ergebnisses eines Zeichenfolgenvergleichs

Ich habe ein Problem mit dieser Zeile (unten kommentiert):

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

welche Ausgängefalse.

Jedoch,System.out.println(s3==s4) Ausgängetrue.

Jetzt kann ich nicht verstehen, warum ich dieses Ergebnis erhalte:

public class string {
    public static void main(String[] args){
        String s3="Shantanu";
        String s4=s3;
        String s1=new String("java");
        String s2=new String("javaDeveloper");

        System.out.println("Using Equals Method::"+s1.equals(s2));
        System.out.println("Using Equals Method::"+s3.equals(s4));
        System.out.println("Using == ::"+s3==s4);//Problem is here in this line
        System.out.println(s1+"Directly printing the s2 value which is autocasted from superclass to string subclass ");
        System.out.println("Directly printing the s1 value which is autocasted from superclass to string subclass "+s2);
        System.out.println(s3);
    }
}
Output-Using Equals Method::false
Using Equals Method::true
Using == ::false
java Directly printing the s2 value which is autocasted from superclass to string subclass
Directly printing the s1 value which is autocasted from superclass to string subclass javaDeveloper

Antworten auf die Frage(3)

Ihre Antwort auf die Frage