Question du test Java

Vérifier si deux chaînes sont égales en Java

Facile

Quel est le résultat du code suivant ?

public static void main(String[] args) {
         String s1 = "java";
         String s2 = "geek";                                                                                                                                                                        
         String s3="Javageek";            
         System.out.println(s3==s1+s2);
    }
Auteur: FodiéStatut : Publiée(Mise à jour)Question passée 87 fois
Modifier
1
Évaluations de la communauté
developer avatar
Auteur anonyme
23/05/2023
Any explication of this ?
developer avatar
Fodié
24/05/2023
In the given code, s1 + s2 will create a new string "javageek". However, the reference of this new string is not the same as the reference of s3, even if their values are equal.