Java Language StringBuilder

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

Java StringBuilder class is used to create mutable (modifiable) string. The Java StringBuilder class is same as StringBuffer class except that it is non-synchronized. It is available since JDK 1.5.

Syntax

  • new StringBuilder ()

  • new StringBuilder (int capacity)

  • new StringBuilder (CharSequence seq)

  • new StringBuilder (StringBuilder builder)

  • new StringBuilder (String string)

  • new StringJoiner (CharSequence delimiter)

  • new StringJoiner (CharSequence delimiter, CharSequence prefix, CharSequence suffix)

Remarks

Creating a new StringBuilder with type char as a parameter would result in calling the constructor with argument int capacity and not the one with argument String string:

 StringBuilder v = new StringBuilder('I'); //'I' is a character, "I" is a String.
 System.out.println(v.capacity()); --> output 73
 System.out.println(v.toString()); --> output nothing



Got any Java Language Question?