Effective way to copy substring without generating garbage
Hi,
I am trying to copy portion of STRING1 to STRINGBUFFER1.
STRINGBUFFER.append(STRING1.substring(from_index, to_index));
However, above method generates a String object, then copy its content to STRINGBUFFER, creating garbage.
Is there some way to do this without generating garbage? Of course, I know I can create a loop and copy one character at a time, but I am afraid that will be slow for huge strings. Thank you in advance.
[462 byte] By [
r11280000a] at [2007-11-27 8:41:16]

> Using bothe StringBuilder and StringBuffer there are multiple ways to do what you want.
> Look at the API.
> There are methods for appending char arrays or ranges of CharSequences to a StringBuffer.
I am sorry I should have mentioned that I am using J2ME, not J2SE. I looked at the API, but could not find anything.
And yes, I am trying to avoid garbage as much as possible, because this code gets called quite often.
Thank you for feedback everyone. I'm still lost with this.