When we extend DefaultHandler, we usually override the characters function.
I was wondering which would be a more efficient way to extract the String supplied…
-
Would it be using a for loop and a StringBuilder?
@Override public void characters(char[] ch, int start, int length) throws SAXException { StringBuilder sb = new StringBuilder(length); for(int i=start; i<start+length; i++) sb.append(ch[i]); String values = sb.toString(); } -
Would it be using a simple substring?
@Override public void characters(char[] ch, int start, int length) throws SAXException { String values = (new String(ch)).substring(start, start + length); } -
Is there another approach?
There is a constructor that takes a char[] and a range, if that is what you are looking for: