When executing string a = "abc";
Time (the precondition is: there is no ABC in the constant pool before executing this line of code, if any, a direct reference in the constant pool ABC does not create an object, if none, execute the following description)
Java Virtual Opportunity creates a char-type value ' A ', ' B ', ' C ' in the stack, and then creates a string in the heap
Object, whose value is the three char type value that you just created in the stack, consists of the array {' A ', ' B ', ' C '}, and finally the newly created string
The object is added to the string pool.
String b = new String ("abc");
, you can create at least one object, or 2
Because the new keyword is used, a string object of B is created in the heap, whose value is "abc", and if the string "ABC" does not exist in the Java string pool, a string object is created in the Java string pool (" ABC ")
String str1 = new String ("ABC"); String str2 = new String ("ABC"); str1 = = is the value of str2 true or false? False.string STR3 = "ABC"; String STR4 = "ABC"; String STR5 = "A" + "BC"; str3 = = is the value of STR4 true or false? TRUE.STR3 = = is the value of STR5 true or false? True. When writing code, do not normally string str2 = new String ("ABC"); String a = "ABC"; String b= "AB"; String c=b+ "C"; System.out.println (A==C); Both Falsea and B are string constants, so they are determined at compile time! A b in C is a reference not a string constant, so it is not determined at compile time.
What is the most efficient way to int to string?
int i = 123;
String s = "";
The first method: s=i+ "";//generates 2 string objects
The second method: s = string.valueof (i); directly using the static method of the String class, producing only one object
String type in Java (don't know how to understand, ask the great God)