Avor Nadal wrote:And second, because String.substring () does not need to copy any array internally, but re-uses the one from the original String and applies limits. I had no idea about this, but it makes sense taking into account that a String is immutable.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Avor Nadal wrote:Do you know the reason behind that surprising change?
Campbell Ritchie wrote:... so your performance improvement vanishes!
Ernest Friedman-Hill wrote:Then you take a 10-character substring out of the middle of the string, and discard the original string object. If the substring() method shares the original string's character array, that 10-character substring is preventing one million characters (two megabytes!) from being garbage collected.
Campbell Ritchie wrote:It also shows that delving too deeply into the innards of a class and trying micro‑optimisation can be counter‑productive. It works well until somebody at the other end realisers, and alters the code, so your performance improvement vanishes!
Consider Paul's rocket mass heater. |