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]
# 1
Does your program crash?Do you run out of memory?Do you really care that an extra String could be created? Rembering that Garbage Collection will free up the memory reasonably quickly (unless for some reason your code maintains a reference to it).
floundera at 2007-7-12 20:40:09 > top of Java-index,Java Essentials,New To Java...
# 2
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.
cotton.ma at 2007-7-12 20:40:09 > top of Java-index,Java Essentials,New To Java...
# 3
Hey cottonDid you see your imposter? http://forum.java.sun.com/thread.jspa?threadID=5187957&tstart=0
floundera at 2007-7-12 20:40:09 > top of Java-index,Java Essentials,New To Java...
# 4
> Hey cotton> > Did you see your imposter?> > http://forum.java.sun.com/thread.jspa?threadID=5187957> &tstart=0No. Bizzare.
cotton.ma at 2007-7-12 20:40:09 > top of Java-index,Java Essentials,New To Java...
# 5

> 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.

r11280000a at 2007-7-12 20:40:09 > top of Java-index,Java Essentials,New To Java...