We are using Java SAX to parser on really big XML files. Our characters
implementation looks like following:
@Override
public void characters(char ch[], int start, int length) throws SAXException {
String value = String.copyValueOf(ch, start, length);
...
}
(ch[]
arrays passed by SAX tend to be pretty long)
But we are recently getting some performance issues and the profiler shows us that over 20% of our CPU usage is above invocation of String.copyValueOf
(which invoked new String(ch,start,length)
under the hood).
Is there any more effective way to obtain a String from array of characters, start index and length than String.copyValueOf(ch, start, length)
or new String(ch,start,length)
?
StringBuilder
?new String(ch,start,length)
just copies the array over but I don't know how fast can aStringBuilder
work. – Forlini