Delete text from StringBuilder


public class Main {
  public static void main(String[] a) {
    StringBuilder builder = new StringBuilder("Line 1\n");

    builder.append("Line 3\n");

    builder.insert(0, "Line 2\n");

    System.out.println(builder.toString());

    builder = builder.delete(2, 6);

    System.out.println(builder.toString());

  }
}

Output:


Line 2
Line 1
Line 3

Li
Line 1
Line 3
Home 
  Java Book 
    Runnable examples  

StringBuilder:
  1. Check the capacity of StringBuilder object
  2. Delete text from StringBuilder
  3. Palindrome with StringBuilder
  4. Remove substring from StringBuilder