In Java, it seems to be String s = "foo"preferable String s = new String("foo").
String s = "foo"
String s = new String("foo")
Why? Is a new string object created in both cases? Why does the first case exclude a constructor call?
Why?
Since the second approach leads to two string objects (the original is due to the string literal plus an explicit copy).
- , . String - , , .
String, , , String. , .
, String ( , , , char , .
, . , "", , , "==", equals, , , . ( == "" )
, , ,
? ?
, , , , :
String s = "foo"; String s2 = "foo";
s == s2 = > true