String object constant pool

The main purpose of the pool is shared for data processing, and 

in the java object pool can be divided into two types:
1, static constant pool: this refers to * automatically saved into the program when .class loaded
string, ordinary constants, class and method information and all assigned by the line

2, runtime constant pool: a * .class after loading, there may be some variables, is performed after receiving the input

 1 package Class_String;
 2 
 3 public class Dome {
 4     public static void main(String[] args) {
 5 
 6         String str1 = "123" ;
 7 
 8         String str2 = "1" + "2" + "3" ;
 9 
10         String str3 = "2" ;
11 
12         String str4 = "1" + str3 + "3" ;
13 
14         System.out.println(str1 == str2);          content given between the Program * All data are constants (constant string objects are anonymous)
. 17/ *1615to true//
 
         
 18          * So when the program loads will automatically help you deal with the appropriate connection
 19          * * / 
20          System.out.println (str1 == str4);   // false 
21          / * 
22          * because the program at load time, the program str3 is uncertain what, because when connected to a string of
 23          * str3 uses a variable, you can modify the contents of the variable, so the final result str3 do not think value is a required
 24          * * / 
25      }
 26 }
 

 

 

Guess you like

Origin www.cnblogs.com/fairy-land/p/11979107.html