String.substring() question

Per Bothner
Wed May 16 17:25:00 GMT 2001

Tom Tromey <> writes:

> Right now String.substring() always creates a reference to the old
> string's data.

No it doesn't:

java::lang::String::substring (jint beginIndex, jint endIndex)
  if (newCount <= 8)  // Optimization, mainly for GC.
    return JvNewString(JvGetStringChars(this) + beginIndex, newCount);

The magic number 8 is somewhat arbitrary - 16 is also reasonable.
But something too much bigger than the String header is probably
a bad idea.
	--Per Bothner

More information about the Java mailing list