Public static void main (String [] args) {
The StringBuilder sb=new StringBuilder (" ABC ");
The update (sb);
System. The out. Println (sb);
}
Public static void update (StringBuilder sb) {
Sb=new StringBuilder (" xyz ");
System. The out. Println (sb);
}
Public static void main (String [] args) {
String STR="a, b, c";
The update (STR);
System. The out. Println (STR);
}
Public static void, update (String STR) {
String STR="x, y, z"
System. The out. Println (STR);
}
CodePudding user response:
Do not have what distinction, you can simply understand the difference between the String and the StringBuilder is roughly equal to the difference between arrays and collectionsCodePudding user response:
From the standpoint of memory, if singleString is immutable, every time is in fact a new object, but a normal String a="213" that are references to the thread pool heap memory overhead is also good
But if the String a=new String (" 123 ") it is a waste of memory, recommend the StringBuilder