Below is a program that demonstrates the most used StringBuilder constructors in Java.

public class Main 
   public static void main(String[] args)
      StringBuilder sb1 = new StringBuilder();
      StringBuilder sb2 = new StringBuilder(5);
      StringBuilder sb3 = new StringBuilder("Hello World");

      System.out.printf("StringBuilder I = \"%s\"\n", sb1);
      System.out.printf("StringBuilder II = \"%s\"\n", sb2);
      System.out.printf("StringBuilder III = \"%s\"\n", sb3);

Related Snippets

Last modified: May 20, 2019


Write a Reply or Comment

Your email address will not be published.