Results 1 to 4 of 4

Thread: String and StringBuffer

  1. #1

    Thread Starter
    Banned debbie_82's Avatar
    Join Date
    Jan 2004
    Location
    inside a hollow void
    Posts
    104

    String and StringBuffer

    Between String and StringBuffer Classes which class executes faster?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Executes what? If you are doing a lot of concatenation, go with a stringbuffer. It doesn't reference new memory every time you reassign it like a string does.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    For concatenation i would think that using a StringBuffer right from the start would allow your code to execute faster since the compiler uses StringBuffers to implement the string concatenation operator.

    String s = "Hello." + "What" + "time" + "is" + "it?";

    // is equivalent to......

    String s2 = new StringBuffer().append("Hello").append("What").append("time").append("is").append("it?").toString();

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Java 1.5 has a new class, StringBuilder, which works exactly like StringBuffer but is not thread-safe and thus faster.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width