From: Tomas Mikula on
Does anyone know what the effective difference between StringWriter and
CharArrayWriter is?

I need a memory-backed writer from which I extract a String at the end. I
see that there are these two choices, so I'm curious about their
performance. I don't need concurrent access to the writer. Is there a
clear preference of which one I should use?

Thanks,
Tomas
From: Roedy Green on
On Fri, 20 Nov 2009 02:59:02 +0000 (UTC), Tomas Mikula
<tomas.mikula(a)gmail.com> wrote, quoted or indirectly quoted someone
who said :

>Does anyone know what the effective difference between StringWriter and
>CharArrayWriter is?

Your IDE should let you look at the source code for both. I suspect
you will find the code is very similar.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Finding a bug is a sign you were asleep a the switch when coding. Stop debugging, and go back over your code line by line.
From: markspace on
Tomas Mikula wrote:
> Does anyone know what the effective difference between StringWriter and
> CharArrayWriter is?
>
> I need a memory-backed writer from which I extract a String at the end. I
> see that there are these two choices, so I'm curious about their
> performance. I don't need concurrent access to the writer. Is there a
> clear preference of which one I should use?


I took a quick look at the source, and both are indeed very similar, as
Roedy opined. I think CharArrayWriter may be very slightly faster, but
it's far from clear to me. Just use which ever, and if needed, profile
and decide based on the profiler results what to do.

From: Arne Vajhøj on
markspace wrote:
> Tomas Mikula wrote:
>> Does anyone know what the effective difference between StringWriter
>> and CharArrayWriter is?
>>
>> I need a memory-backed writer from which I extract a String at the
>> end. I see that there are these two choices, so I'm curious about
>> their performance. I don't need concurrent access to the writer. Is
>> there a clear preference of which one I should use?
>
> I took a quick look at the source, and both are indeed very similar, as
> Roedy opined. I think CharArrayWriter may be very slightly faster, but
> it's far from clear to me. Just use which ever, and if needed, profile
> and decide based on the profiler results what to do.

Or don't bother.

One may be slightly faster than the other on a given Java
version on a given platform.

But that does not guarantee that all the systems the
code will run the next 10 years will have the same
performance characteristics.

Arne