Reading Li Jianzhong Instructor'sProxyDuring the Agent Mode Course, I heard about it.StringType andStringbuilderType. We have a new understanding of the implementation of these two types.
I have read aboutStringType of data,StringType, it gives me the impression that it is used with caution, otherwise the memory will produce a lot of garbage. The key issue lies inStringObject modification.
When we instantiateStringIn memory, allocate a space for this object. As follows:
String strtest = "AA ";
When we modifyStrtestFor example:Strtest = "BB ";In this caseStrtestAllocate a new space. In this way, the original memory space is wasted and can only be recycled by the garbage collector. I found someCodeFrequently modifiedStringObject value, for example:
String strsql = "Select ....";
Strsql + = "...";
Strsql + = "...";
Strsql + = "...";
...
In fact, this is a waste of memory space. If this is the case frequently, we recommend that you useStringbuilderObject, but if the number of times the string is frequently accumulated is not many, it is actually usedStringbuilderIt is counterproductive. I think this can be written in the following situations:
String strsql = "Select..." + "..." + ...;
This will provide better performance.
This time Li Jianzhong The instructor explainedCopy-to-writeTechnology. For twoStringType variables are as follows:
String str1 = "AA ";
String str2 = "AA ";
When the twoStringWhen the values of type variables are the same, they actually point to the same memory space, for example:
ForStringbuilderThe object is like this, for example, there are twoStringbuilderObject
Stringbuilder SB1 = new stringbuilder ("AA ")
Stringbuilder sb2 = new stringbuilder ("AA ")
Their status in memory is as follows:
WhenSb2Only modifySb2. For example
From: http://www.cnblogs.com/wayne-ivan/archive/2006/10/18/532320.html
PS: I am also a student of Li Jianzhong, so of course I can support it!