// DO NOT DO THIS. It is quadratic-time!
StringBuilder sb = new StringBuilder();
for(int i=0;i<100;i++){
    sb.insert(0, Integer.toString(i));
}

Warning: It defeats the purpose of StringBuilder, but it does what you asked.


Better technique (although still not ideal):

  1. Reverse each string you want to insert.
  2. Append each string to a StringBuilder.
  3. Reverse the entire StringBuilder when you're done.

This will turn an O(n²) solution into O(n).

Answer from user541686 on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › StringBuilder.html
StringBuilder (Java Platform SE 8 )
July 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.
🌐
Codecademy
codecademy.com › docs › java › stringbuilder › .insert()
Java | StringBuilder | .insert() | Codecademy
August 22, 2022 - The .insert() method places a sequence of characters into the StringBuilder and returns a reference to the object.
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuilder-class-in-java-with-examples
StringBuilder Class in Java - GeeksforGeeks
StringBuilder is a mutable sequence of characters provided by the java.lang package. Unlike String, its contents can be modified without creating a new object for every operation.
Published: September 1, 2026
🌐
Tutorialspoint
tutorialspoint.com › java › lang › stringbuilder_insert_char.htm
Java.lang.StringBuilder.insert() Method
The java.lang.StringBuilder.insert(int offset, char c) method inserts the string representation of the char argument into this sequence. The second argument is inserted into the contents of this sequence at the position indicated by offset.
🌐
Hyperskill
hyperskill.org › university › java › java-stringbuilder
Java StringBuilder
December 4, 2024 - StringBuilder insert(int offset, String str) inserts the given string into the existing StringBuilder object at the given position indicated by the offset.
Find elsewhere
🌐
Medium
writethatcode.medium.com › string-builders-append-vs-insert-148c0c662662
String Builder’s Append Vs Insert | by Lakshmanan Subbiah | Medium
February 28, 2021 - I have performed a custom implementation of StringBuilder, you can find it here. On benchmarking the string Builder class I get the insert method takes 1700 milliseconds on average to perform 100000 inserts and append takes only 3 milliseconds to perform the same amount of appends.
🌐
BeginnersBook
beginnersbook.com › 2022 › 10 › java-stringbuilder-insert
Java StringBuilder insert()
October 4, 2022 - //insert string "hello" at the position (index) 1 sb.insert(1, "hello"); //insert integer 100 at the index 2 sb.insert(2, 100); //insert boolean 'true' at the end of StringBuilder instance sb.insert(sb.length(), true);
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.text.stringbuilder
StringBuilder Class (System.Text) | Microsoft Learn
The AppendFormat method appends a composite format string to a StringBuilder object. The string representations of objects included in the result string can reflect the formatting conventions of the current system culture or a specified culture. The Insert method inserts a string, a substring, multiple repetitions of a string, a character array, a portion of a character array, or the string representation of a primitive data type at a specified position in the StringBuilder object.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › stringbuilder_insert.htm
Java StringBuilder insert() Method
The Java StringBuilder insert() method is used to insert a string passed argument into a StringBuilder object. The insert() method accepts different types of an argument, such as Boolean, int, char, and so on.
🌐
Java Guides
javaguides.net › 2024 › 06 › java-stringbuilder-insert-method.html
Java StringBuilder insert() Method
June 10, 2024 - The StringBuilder.insert() method in Java is used to insert various types of data into a StringBuilder object at a specified position.
🌐
Scijava
javadoc.scijava.org › Java7 › java › lang › class-use › StringBuilder.html
Uses of Class java.lang.StringBuilder (Java Platform SE 7 )
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
🌐
Lwkzeb
lwkzeb.my › !2ej2 › 7wqqeuryn3oqhqtg3032.atom
Stringbuilder java insert - lwkzeb.my
Press "Allow" to confirm · I am not a Robot · Click on "Allow" to confirm that you are not a robot
🌐
Lancaster Archery Supply
lancasterarchery.com › pages › easton-archery-free-gift-offer
Easton Archery Free Gift Offer – Lancaster Archery Supply
Inserts, Outserts & Halfouts · Point & Insert Weights · Arrow Wraps & Numbers · Shop All Arrow Building & Repair · Adhesives, Glue & Epoxy · Fletching Jigs · Arrow Building & Repair Tools · Arrow Cut-Off Saws · Grain Scales & Spine Testers · Feather Treatment ·