The structure of a string in memory
Note: The variable name declared by the string class is placed in the stack, the new object is placed in the heap, and the string concrete constant class is placed in the constant pool
B. String is an immutable object
the Java.lang.String class uses the final decoration and cannot be inherited. A string is a constant whose object can no longer be changed once it is constructed.
package Com.yyx.pratice; public class teststring { public static void main (string[] args) {S Tring str1 = "Hello World" ; System.out.println (STR1); String str2 = upcase (STR1); System.out.println (STR2); System.out.println (STR1); public static string upcase (string s) { return S.touppercase (); }}
Iii. number of objects created
1.String a = new String ("1" + "2") build up several objects?
2 objects were created, because the compiler would merge the right side of the equals sign, so he would create a "12" string in the constant area, and then, creating an object on the heap called a
2.String str=new String ("abc") how many objects do you build?
2 objects created
Deep understanding of string in Java