First, String s=new string ("abc"); The sentence creates 2 objects;
One instance object for new and the other is "ABC";
S is not an object, S is just a reference (a pointer in C + +).
To query the constructor of the string class in Java, there is one such constructor with the following API:
Public (original)
Initializes a newly created String
object to represent a sequence of characters that are the same as the argument; in other words, the newly created string is a copy of the parameter string. Because the String is immutable, you do not need to use this construction method unless you want original
an explicit copy.
Parameters:
original
-A String
.
The string s= "abc" apparently created only one object.
String s= "A" + "B"; This sentence creates 3 objects, "a" "B" and "AB"
Secondly, the difference between the two is as follows:
String S=new string ("abc"); The resulting object will not be in the JVM (Java Virtual machine) Chang (precompiled)
and the latter is. (Note: The String class is a final type and the String class object cannot be modified.)
Reference: http://www.cnblogs.com/ydpvictor/archive/2012/09/09/2677260.html
"Java Heavy Difficulty Knowledge" string S=new string ("abc") and string= "ABC"; Difference