StringBuilder: insert(int offset, String str)
public class Main {
public static void main(String[] a) {
StringBuilder builder = new StringBuilder("Line 1\n");
builder.append("Line 3\n");
String lineToInsert = "Line 2\n";
builder.insert(0, lineToInsert);
System.out.println(builder.toString());
}
}
/*
Line 2
Line 1
Line 3
*/
Related examples in the same category