You should use the StringBuilder class.
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Some text");
stringBuilder.append("Some text");
stringBuilder.append("Some text");
String finalString = stringBuilder.toString();
In addition, please visit:
- "How Java optimize the code with StringBuilder?"
- "StringBuilder vs String concatenation in toString() in Java"
GeeksforGeeks
geeksforgeeks.org › java › stringbuilder-append-method-in-java-with-examples
StringBuilder append() Method in Java - GeeksforGeeks
July 11, 2025 - In Java, the append() method of StringBuilder class is used to add data to the end of an existing StringBuilder object.
Codecademy
codecademy.com › docs › java › stringbuilder › .append()
Java | StringBuilder | .append() | Codecademy
August 22, 2022 - The .append() method appends the string value of its argument to the StringBuilder. It returns a reference to the StringBuilder object. ... Looking for an introduction to the theory behind programming?
Videos
20:34
Learn Java Programming - StringBuilder .append() Method Tutorial ...
04:17
How to Append Text to an Existing File in Java - YouTube
01:59
JAVA || How to append to a string - YouTube
02:15
#123 Java Append to File – Add Text Without Overwriting (FileWriter ...
02:44
StringBuilder append() Method in Java With Examples - YouTube
05:43
Beginner Java - String Append - Lesson 26 - YouTube
How can I append custom objects using StringBuilder?
StringBuilder automatically invokes the toString() method on custom objects when appending them. If the default toString() implementation is not suitable, override the method in your custom class. This allows for better control over how objects are appended as strings. It ensures the output is meaningful and formatted as needed.
upgrad.com
upgrad.com › home › blog › software development › enhance string handling with append in java for efficient code!
Enhance Java Performance with Append in Java for Speed!
Does the append() method affect the original string object?
No, the append() method does not alter the original string. Instead, it modifies the internal buffer of StringBuilder or StringBuffer. The original string object remains unchanged throughout the process. This ensures the method does not create new objects or incur additional memory costs.
upgrad.com
upgrad.com › home › blog › software development › enhance string handling with append in java for efficient code!
Enhance Java Performance with Append in Java for Speed!
What is the difference between StringBuilder and StringBuffer in Java?
StringBuilder is faster for single-threaded environments due to no synchronization overhead. In contrast, StringBuffer is synchronized and thread-safe. This makes StringBuffer suitable for multi-threaded applications. For single-threaded operations, StringBuilder offers better performance with less memory usage.
upgrad.com
upgrad.com › home › blog › software development › enhance string handling with append in java for efficient code!
Enhance Java Performance with Append in Java for Speed!
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.
Top answer 1 of 5
115
You should use the StringBuilder class.
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Some text");
stringBuilder.append("Some text");
stringBuilder.append("Some text");
String finalString = stringBuilder.toString();
In addition, please visit:
- "How Java optimize the code with StringBuilder?"
- "StringBuilder vs String concatenation in toString() in Java"
2 of 5
36
Use StringBuilder class. It is more efficient at what you are trying to do.
Tutorialspoint
tutorialspoint.com › java › lang › stringbuilder_append_string.htm
Java.lang.StringBuilder.append() Method
The java.lang.StringBuilder.append(String str) method appends the specified string to this character sequence.The characters of the String argument are appended, in order, increasing the length of this sequence by the length of the argument.
Tutorialspoint
tutorialspoint.com › java › stringbuffer_append.htm
Java - String Buffer append() Method
Java Vs. C++ ... This method updates the value of the object that invoked the method. The method takes boolean, char, int, long, Strings, etc. Here is a separate method for each primitive data type − · public StringBuffer append(boolean b) public StringBuffer append(char c) public StringBuffer append(char[] str) public StringBuffer append(char[] str, int offset, int len) public StringBuffer append(double d) public StringBuffer append(float f) public StringBuffer append(int i) public StringBuffer append(long l) public StringBuffer append(Object obj) public StringBuffer append(StringBuffer sb) public StringBuffer append(String str)
GeeksforGeeks
geeksforgeeks.org › java › stringbuffer-append-method-in-java-with-examples
StringBuffer append() Method in Java with Examples - GeeksforGeeks
July 11, 2025 - public StringBuffer append(int a) Parameter: The method accepts a single parameter a which is the int value. Return Value: The method returns a reference to this object. Examples : Input : StringBuffer = I love my Country int a = 55 Output: I love my Country 55 Below program illustrates the java.lang.StringBuffer.append() method.
CodeSignal
codesignal.com › learn › courses › fundamentals-of-text-data-manipulation-in-java-1 › lessons › writing-and-appending-text-files-in-java-1
Writing and Appending Text Files in Java
Sometimes, you may want to add data to an existing file without overwriting its current contents. This can be easily achieved in Java using the Files.write method with the StandardOpenOption.APPEND flag.
W3Schools
w3schools.com › java › java_strings_concat.asp
Java Strings Concatenation
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
Java-samples
java-samples.com › showtutorial.php
append() in Java
The append() method concatenates the string representation of any other type of data to the end of the invoking StringBuffer object. It has overloaded versions for all the built-in types and for Object. Here are a few of its forms:
GeeksforGeeks
geeksforgeeks.org › java › list-add-method-in-java-with-examples
List add() Method in Java with Examples - GeeksforGeeks
July 11, 2025 - The List add() method adds (appends) an element to a list. It can be used for both ArrayList and LinkedList. ... // Java program to demonstrate // ArrayList usage import java.io.*; import java.util.ArrayList; import java.util.List; class GFG ...
BeginnersBook
beginnersbook.com › 2014 › 08 › java-stringbuilder-append-char-c-method
Java – StringBuilder.append(char c) Method
October 6, 2022 - public class JavaExample { public static void main(String[] args) { StringBuilder sb = new StringBuilder("BeginnersBook"); System.out.println("Sequence :"+sb); char[] chArray = {'a','b','c','.','c','o','m'}; // appending elements of char array from 4th till 7th sb.append(chArray, 3, 4); System.out.println("New Sequence: " + sb); } }
BeginnersBook
beginnersbook.com › 2022 › 10 › java-stringbuffer-append-method
Java StringBuffer append() Method
October 9, 2022 - public class JavaExample { public static void main(String[] args) { StringBuffer sb = new StringBuffer("BeginnersBook"); System.out.println("Sequence :"+sb); char[] chArray = {'a','b','c','.','c','o','m'}; // appending elements of char array from 4th till 7th sb.append(chArray, 3, 4); System.out.println("New Sequence: " + sb); } }
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-append-a-string-in-an-existing-file
Java Program to Append a String in an Existing File - GeeksforGeeks
July 11, 2025 - file out.write("Hello World:\n"); // Closing file connections out.close(); } // Catch block to handle exceptions catch (IOException e) { // Display message when error occurs System.out.println("Exception Occurred" + e); } // Now appendinggiven str to above // created file String str = "This is GeeksforGeeks"; // Calling the above method appendStrToFile(fileName, str); // Let us print modified file try { BufferedReader in = new BufferedReader( new FileReader("Geek.txt")); String mystring; // TIll there is content in string // condition holds true while ((mystring = in.readLine()) != null) { System.out.println(mystring); } } // Catch block to handle IO exceptions catch (IOException e) { System.out.println("Exception Occurred" + e); } } }