3 Replies Latest reply: Jan 20, 2007 8:13 AM by 3004 RSS

    String and Stringbuffer

    807607
      I could see that Stringbuffer is better always compared to String in performance and all that String offers is satisfied by Stringbuffer but still the usage of string is more and also why this is not depricated .any comments ?
        • 1. Re: String and Stringbuffer
          807607
          Multipost: http://forum.java.sun.com/thread.jspa?messageID=9451246

          No help for you!
          • 2. Re: String and Stringbuffer
            807607
            It makes no sense to say that one is better than the other without saying what you're using them for. If you don't have a specific reason for using a StringBuffer, use a String. Now, if you were comparing StringBuffer to StringBuilder, that would make sense, because those two classes do serve the same purpose. The only difference is that StringBuffer is thread-safe; if you don't need that feature, you should probably use StringBuilder.
            • 3. Re: String and Stringbuffer
              3004
              I could see that Stringbuffer is better always
              compared to String in performance and all that String
              offers is satisfied by Stringbuffer but still the
              usage of string is more and also why this is not
              depricated .any comments ?
              You're not considering design aspects. String is immutable (which StringBuffer isn't) and that's sometimes an advantage bordering to a necessity. It's for example generally a very bad idea to use StringBuffer objects as keys in Maps.