Effective method for creating string from char [], start, length
We are using java Sax to parse very large XML files Our roles are as follows:
@Override public void characters(char ch[],int start,int length) throws SAXException { String value = String.copyValueOf(ch,start,length); ... }
(the ch [] array passed by Sax is often very long)
However, we recently encountered some performance problems, and the analyzer showed us that more than 20% of the CPU utilization is higher than that of string Call to copyvalueof (it calls a new string (CH, length))
Is there a more effective way to get string from character array, starting index and length than string Copyvalueof (CH, length) or new string (CH, length)?
Solution
Good question, but I'm sure the answer is yes
This is because any string object construction uses the array copy method It cannot be constructed directly on an existing array because the string object must be immutable and its internal string array representation is encapsulated by external changes
In addition, in your case, you process fragments of an array It is impossible to build a string object on a fragment of another array in any way