Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: stringbuilder and string buffer

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default stringbuilder and string buffer

    what is the difference between stringbuffer and string builder?


  2. #2
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: stringbuilder and string buffer

    Visit these links below to know the answer.
    StringBuffer (Java Platform SE 7 )
    StringBuilder (Java Platform SE 7 )

  3. The Following User Says Thank You to dicdic For This Useful Post:

    kanupriya1 (April 3rd, 2014)

  4. #3
    Junior Member
    Join Date
    Apr 2014
    Location
    Pune,Maharashtra
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: stringbuilder and string buffer

    Simply use StringBuilder unless you really are trying to share a buffer between threads. StringBuilder is the unsynchronized (less overhead = more efficient) younger brother of the original synchronized StringBuffer class.

    StringBuffer came first. Sun was concerned with correctness under all conditions, so they made it synchronized to make it thread-safe just in case.

    StringBuilder came later. Most of the uses of StringBuffer were single-thread and unnecessarily paying the cost of the synchronization.

    Since StringBuilder is a drop-in replacement for StringBuffer without the synchronization, there would not be differences between any examples.

    If you are trying to share between threads, you can use StringBuffer, but consider whether higher-level synchronization is necessary, e.g. perhaps instead of using StringBuffer, should you synchronize the methods that use the StringBuilder.

Similar Threads

  1. what is string and StringBuffer and StringBuilder?
    By shirin in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 4th, 2014, 08:03 AM
  2. Finding a word within a string (using a stringbuilder)
    By getaway in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 9th, 2013, 10:20 AM
  3. [SOLVED] difference between String Concatenation and String -Buffer/Builder .append(<value>)
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: September 3rd, 2011, 08:16 AM
  4. How to reverse a String using java.lang.StringBuilder
    By JavaPF in forum Java SE API Tutorials
    Replies: 0
    Last Post: July 22nd, 2009, 09:42 AM
  5. How to reverse a String using java.lang.StringBuilder
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: July 22nd, 2009, 09:42 AM