CKTIS / Java
StringBuilder.append — appending text
StringBuilder.append(String) adds text to the end of an existing builder and returns that same object, allowing calls to be chained.
Version: Java SE 21; repository runtime, production runtime not attested
Syntax
public StringBuilder append(String str)StringBuilder.append has several overloads. The append(String str) overload appends the characters of str in order. It modifies the existing builder and returns a reference to that same object, allowing chained calls.
A String argument whose value is null appends the four characters "null". In the example, missing is explicitly typed as String, selecting the appropriate overload. toString() returns the result as a String.
StringBuilder is not safe to share between threads without synchronization.
Examples
public class Main {
public static void main(String[] args) {
StringBuilder builder = new StringBuilder("Hello");
String missing = null;
builder.append(", ").append("Java").append("! ").append(missing);
System.out.println(builder.toString());
}
}Result
Hello, Java! null
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.