🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › StringBuffer.html
StringBuffer (Java Platform SE 8 )
April 21, 2026 - Java™ Platform Standard Ed. 8 ... A thread-safe, mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuffer-class-in-java
StringBuffer Class in Java - GeeksforGeeks
import java.io.* ; class Geeks ... of the StringBuffer class returns the current capacity of the buffer. The default capacity of the buffer is 16....
Published   May 27, 2026
Discussions

optimization - Why to use StringBuffer in Java instead of the string concatenation operator - Stack Overflow
They avoid performing an allocation ... their buffer by a proportion of its current size, giving amortized O(1) appending. However its worth noting that often the compiler will be able to optimise code into StringBuilder style (or better - since it can perform constant folding etc.) automatically. ... Save this answer. ... Show activity on this post. Java turns string1 ... More on stackoverflow.com
🌐 stackoverflow.com
Do I need to use a StringBuffer in 2018 Javascript?
String manipulation in JS is stupid fast. I once tried to build something along the lines you are describing, but it was about 20% slower than just using a bunch of + operators. :P More on reddit.com
🌐 r/javascript
7
1
December 6, 2018
String Builder or String Buffer?
StringBuilder. Never use StringBuffer. Even if you need to concurrent append string information, synchronizing on a StringBuilder allows you make multiple atomic appends rather than StringBuffer's per-method synchronization. Never use StringBuffer. More on reddit.com
🌐 r/androiddev
11
6
February 8, 2018
String buffer Cesar Cypher (need material to self teach stringbuffer/to know if it's possible like this)
You absolutely do not need a special "course/tutorial" for StringBuffer. It is one of the simpler classes. The official Documentation: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/StringBuffer.html is all you need. You create the StringBuffer instance, append to it, and when you're finished, you convert it to a String with .toString. That's it. More on reddit.com
🌐 r/javahelp
5
2
November 21, 2024
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › lang › StringBuffer.html
StringBuffer (Java SE 11 & JDK 11 )
January 20, 2026 - A thread-safe, mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › StringBuffer.html
StringBuffer (Java Platform SE 7 )
Java™ Platform Standard Ed. 7 ... A thread-safe, mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.stringbuffer
StringBuffer Class (Java.Lang) | Microsoft Learn
The principal operations on a StringBuffer are the append and insert methods, which are overloaded so as to accept data of any type. Each effectively converts a given datum to a string and then appends or inserts the characters of that string to the string buffer.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › java_lang_stringbuffer.htm
Java StringBuffer Class
The Java StringBuffer class is mutable sequence of characters. StringBuffer can be used to modify the content of a String with ease. It provides many utility functions to manipulate a string.
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › lang › StringBuffer.html
StringBuffer (Java SE 21 & JDK 21)
January 20, 2026 - A thread-safe, mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
🌐
Mankarcollege
mankarcollege.ac.in › studyMaterial › 101741string-buffer-class.pdf pdf
Java StringBuffer class
Java StringBuffer class is used to create mutable (modifiable) string. The StringBuffer class in java
Find elsewhere
🌐
DataFlair
data-flair.training › blogs › stringbuffer-in-java
StringBuffer in Java - Explore its Constructors & Methods with Examples - DataFlair
May 14, 2018 - StringBuffer in Java allows to append, replace, reverse, concatenate strings. Learn about constructors and methods in java StringBuffer.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › StringBuffer.html
StringBuffer (Java SE 17 & JDK 17)
April 21, 2026 - A thread-safe, mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
🌐
NxtWave
ccbp.in › blog › articles › string-buffer-in-java
String Buffer in Java: Features, Constructors & Key Methods
One of the most significant classes ... String Buffer. The String Buffer provides a changeable method of handling strings that permits dynamic updates without generating additional objects, in contrast to the immutable String ...
🌐
Tutorialspoint
tutorialspoint.com › java › java_string_buffer.htm
String Buffer and String Builder Classes
public class Test { public static void main(String args[]) { StringBuffer sBuffer = new StringBuffer("test"); sBuffer.append(" String Buffer"); System.out.println(sBuffer); } }
🌐
Oracle
docs.oracle.com › en › java › javase › 23 › docs › api › java.base › java › lang › StringBuffer.html
StringBuffer (Java SE 23 & JDK 23)
October 17, 2024 - A thread-safe, mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
🌐
Oracle
docs.oracle.com › javame › config › cldc › ref-impl › cldc1.0 › jsr030 › java › lang › StringBuffer.html
java.lang Class StringBuffer
A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
🌐
Medium
medium.com › @brandon93.w › stringbuilder-and-stringbuffer-in-java-examples-and-interview-exercises-fd735f15c415
StringBuilder and StringBuffer in Java: Examples and Interview Exercises | by Brandon Wohlwend | Medium
August 8, 2023 - StringBuilder and StringBuffer in Java: Examples and Interview Exercises Welcome back studying with me Java! In programming, mastering the art of string manipulation is crucial. It is not just about …
🌐
Scaler
scaler.com › home › topics › java › stringbuffer class in java
StringBuffer Class in Java Class - Scaler Topics
February 11, 2022 - Let's understand the method of StringBuffer in java ... The string "sh" is returned because we want substring starting from index 4, and "yus" is returned because the index of y is two and the ending index is 4. That's why we get substring "yus". This method is used for deleting the whole sequence from the buffer ...
🌐
MIT
web.mit.edu › java_v1.0.2 › www › javadoc › java.lang.StringBuffer.html
Class java.lang.StringBuffer
Ensures that the capacity of the buffer is at least equal to the specified minimum. ... Copies the characters of the specified substring (determined by srcBegin and srcEnd) into the character array, starting at the array's dstBegin location. ... Inserts a boolean into the String buffer.
🌐
TechVidvan
techvidvan.com › tutorials › java-stringbuffer-class
Java StringBuffer Class with Example - TechVidvan
June 11, 2020 - Hence, considering this Java provides a class StringBuffer that gives the facility to create a sequence of characters with mutable (modifiable) attributes. In Java, the class has two main pointers which are used to define a class: ... So, let’s dive deep into the StringBuffer class. This constructor creates an empty string buffer with an initial space of 16 characters.
🌐
Bureau of Economic Geology
beg.utexas.edu › lmod › agi.servlet › doc › detail › java › lang › StringBuffer.html
java.lang Class StringBuffer
A string buffer implements a mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
Top answer
1 of 16
68

It's better to use StringBuilder (it's an unsynchronized version; when do you build strings in parallel?) these days, in almost every case, but here's what happens:

When you use + with two strings, it compiles code like this:

String third = first + second;

To something like this:

StringBuilder builder = new StringBuilder( first );
builder.append( second );
third = builder.toString();

Therefore for just little examples, it usually doesn't make a difference. But when you're building a complex string, you've often got a lot more to deal with than this; for example, you might be using many different appending statements, or a loop like this:

for( String str : strings ) {
  out += str;
}

In this case, a new StringBuilder instance, and a new String (the new value of out - Strings are immutable) is required in each iteration. This is very wasteful. Replacing this with a single StringBuilder means you can just produce a single String and not fill up the heap with Strings you don't care about.

2 of 16
45

For simple concatenations like:

String s = "a" + "b" + "c";

It is rather pointless to use StringBuffer - as jodonnell pointed out it will be smartly translated into:

String s = new StringBuffer().append("a").append("b").append("c").toString();

BUT it is very unperformant to concatenate strings in a loop, like:

String s = "";
for (int i = 0; i < 10; i++) {
    s = s + Integer.toString(i);
}

Using string in this loop will generate 10 intermediate string objects in memory: "0", "01", "012" and so on. While writing the same using StringBuffer you simply update some internal buffer of StringBuffer and you do not create those intermediate string objects that you do not need:

StringBuffer sb = new StringBuffer();
for (int i = 0; i < 10; i++) {
    sb.append(i);
}

Actually for the example above you should use StringBuilder (introduced in Java 1.5) instead of StringBuffer - StringBuffer is little heavier as all its methods are synchronized.