difference between StringWriter and CharArrayWriter?

T

Tomas Mikula

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
 
R

Roedy Green

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

markspace

Tomas said:
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.
 
A

Arne Vajhøj

markspace said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top