difference between StringWriter and CharArrayWriter?

Discussion in 'Java' started by Tomas Mikula, Nov 20, 2009.

  1. Tomas Mikula

    Tomas Mikula Guest

    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
    Tomas Mikula, Nov 20, 2009
    #1
    1. Advertising

  2. Tomas Mikula

    Roedy Green Guest

    On Fri, 20 Nov 2009 02:59:02 +0000 (UTC), Tomas Mikula
    <> 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.
    Roedy Green, Nov 20, 2009
    #2
    1. Advertising

  3. Tomas Mikula

    markspace Guest

    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.
    markspace, Nov 20, 2009
    #3
  4. 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
    Arne Vajhøj, Nov 21, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jakk
    Replies:
    4
    Views:
    12,039
  2. Replies:
    1
    Views:
    754
    intrader
    Jun 17, 2005
  3. fabrice
    Replies:
    4
    Views:
    2,298
    fabrice
    Nov 15, 2006
  4. darrel
    Replies:
    3
    Views:
    637
    Cowboy \(Gregory A. Beamer\)
    Mar 27, 2007
  5. Replies:
    6
    Views:
    7,901
    Tom Anderson
    Mar 30, 2009
Loading...

Share This Page