StringBuilder class constructors in Java

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

Tutorials Panel

About Tutorials Panel

programming tutorial and source code for Software Engineers and developers.

View all posts by Tutorials Panel →

Leave a Reply