StringBuilder: toString() : StringBuilder « java.lang « Java by API






StringBuilder: toString()

 

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

1.new StringBuilder(String str)
2.new StringBuilder(int capacity)
3.StringBuilder: append(char c)
4.StringBuilder: capacity()
5.StringBuilder: delete(int start, int end)
6.StringBuilder: insert(int offset, String str)
7.StringBuilder: reverse()