Simplest way to append is just using + as in s = s + c. This isn't the best way to do it performance wise since a new String is created every time (due to Strings being immutable). Instead you may use a StringBuilder e.g.

//Create outside of loop
StringBuilder sb = new StringBuilder();
//Append in loop
sb.append(c);
//Print when done
System.out.println(sb);
//Return the String to the caller
return sb.toString();
Answer from Jotunacorn on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › StringBuilder.html
StringBuilder (Java Platform SE 8 )
April 21, 2026 - The principal operations on a StringBuilder 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 builder.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › fundamentals › code-analysis › quality-rules › ca1834
CA1834: Use StringBuilder.Append(char) for single character strings (code analysis) - .NET | Microsoft Learn
April 2, 2026 - using System; using System.Text; namespace TestNamespace { public class Program { public const string unitString = "a"; static void Main(string[] args) { StringBuilder sb = new StringBuilder(); sb.Append(unitString); } } } After careful analysis, unitString here can be changed to a char without causing any build errors.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › stringbuilder_append_char.htm
Java.lang.StringBuilder.append() Method
The java.lang.StringBuilder.append(char c) method appends the string representation of the char argument to this sequence.The argument is appended to the contents of this sequence.
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuilder-append-method-in-java-with-examples
StringBuilder append() Method in Java - GeeksforGeeks
July 11, 2025 - This version appends a subsequence of characters from a CharSequence to the StringBuilder by using specified start and end indices.
🌐
BeginnersBook
beginnersbook.com › 2014 › 08 › java-stringbuilder-append-char-c-method
Java – StringBuilder.append(char c) Method
October 6, 2022 - public StringBuilder append(char c): This method appends specified char c at the end of the char sequence represented by StringBuilder object. There are several variations of this method that allow various data types to be appended.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › StringBuilder.html
StringBuilder (Java Platform SE 7 )
The principal operations on a StringBuilder 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 builder.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.text.stringbuilder.append
StringBuilder.Append Method (System.Text) | Microsoft Learn
The Append(Char[], Int32, Int32) method modifies the existing instance of this class; it does not return a new class instance. Because of this, you can call a method or property on the existing reference and you do not have to assign the return ...
Find elsewhere
🌐
Medium
medium.com › @AlexanderObregon › javas-stringbuilder-append-method-explained-500b2ef84ec0
Java’s StringBuilder.append() Method Explained | Medium
August 6, 2024 - StringBuilder sb = new StringBuilder(50); // Initial capacity of 50 characters · If the capacity is not specified, a default value is used. If the number of characters appended exceeds the current capacity, the StringBuilder automatically increases its capacity.
🌐
Codecademy
codecademy.com › docs › java › stringbuilder › .append()
Java | StringBuilder | .append() | Codecademy
August 22, 2022 - ** For char[] arguments, .append() can have two additional optional int arguments: ... In this case, .append() will append the subsequence defined by the start point and length specified by start and len. The following example creates a StringBuilder with a specified String and then uses the .append() method to change it:
🌐
Andrew Lock
andrewlock.net › a-deep-dive-on-stringbuilder-part-2-appending-strings-built-in-types-and-lists
Appending strings, built-in types, and lists: A deep dive on StringBuilder - Part 2
July 20, 2021 - As for Append(string) at the start of this post, AppendJoin() again uses an unsafe context, creating a fixed pointer for the backing char[] representing the separator values (", " in my example above). It then calls AppendJoinCore<T>(), passing in the pointer, the length of the string, and the values to append. AppendJoinCore<T>() is shown below: private unsafe StringBuilder AppendJoinCore<T>(char* separator, int separatorLength, T[] values) { if (values.Length == 0) { return this; } if (values[0] != null) { Append(values[0]!.ToString()); } for (int i = 1; i < values.Length; i++) { Append(separator, separatorLength); if (values[i] != null) { Append(values[i]!.ToString()); } } return this; }
🌐
Stack Overflow
stackoverflow.com › questions › 59230474 › stringbuilder-append-2-chars-or-1-string
java - StringBuilder - Append 2 char's or 1 String - Stack Overflow
When working with a StringBuilder, I often append 2 char values to a StringBuilder using StringBuilder#append(char) twice, rather than StringBuilder#append(String). I.e.: StringBuilder builder =...
🌐
TutorialKart
tutorialkart.com › java › java-stringbuilder-append
Java StringBuilder.append() - Syntax & Examples
January 24, 2021 - StringBuilder.append() appends the string representation of the char argument to the existing sequence in this StringBuilder object.
🌐
Jnior
jnior.com › jnior › janos-runtime-javadoc › java › lang › StringBuilder.html
StringBuilder (JanosRuntime JavaDOC)
public StringBuilder append(char c) Appends character to content. Parameters: c - character value to append · Returns: this · public StringBuilder append(int i) Appends the value of (@code int) to content. Parameters: i - (@code int) value whose textual representation is to be appended ·
🌐
Oracle
docs.oracle.com › javase › 6 › docs › api › java › lang › StringBuilder.html
StringBuilder (Java Platform SE 6)
The principal operations on a StringBuilder 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 builder.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.stringbuilder.append
StringBuilder.Append Method (Java.Lang) | Microsoft Learn
Appends the string representation of the specified char value. [Android.Runtime.Register("append", "(C)Ljava/lang/StringBuilder;", "")] public override Java.Lang.IAppendable Append(char c);
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuilder-class-in-java-with-examples
StringBuilder Class in Java - GeeksforGeeks
The append() method adds the given string to the end of the existing sequence without creating a new object. This makes StringBuilder efficient for concatenation operations. It extends the AbstractStringBuilder class and implements the CharSequence ...
Published   May 8, 2026
🌐
Oracle
docs.oracle.com › javase › tutorial › java › data › buffers.html
The StringBuilder Class (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
The append method always adds these characters at the end of the existing character sequence, while the insert method adds the characters at a specified point. Here are a number of the methods of the StringBuilder class.
🌐
Baeldung
baeldung.com › home › java › java string › how to append a newline to a stringbuilder
How to Append a Newline to a StringBuilder | Baeldung
September 25, 2024 - An alternative approach is to use System.getProperty(“line.separator”), which returns the newline character specific to the system we’re running on: StringBuilder sb = new StringBuilder(); sb.append("First Line"); sb.append(System.getProperty("line.separator")); sb.append("Second Line"); Although System.getProperty(“line.separator”) works the same way as System.lineSeparator(), it’s less commonly used because System.lineSeparator() was introduced as a cleaner solution in Java 7.