Java StringBuilder

| Page Views: 22

Java provides us with an intuitive way of creating and working with sequence of characters that can be modified.

StringBulilder as class derives from AbstractStringBuilder.

public final class StringBuilder extends AbstractStringBuilder {}

It implements and java.lang.CharSequence.

public final class StringBuilder extends AbstractStringBuilder implements Serializable, CharSequence {}

StringBuilder resides in the java.lang package.

package java.lang;

Creating a StringBuilder.

StringBuilder provides several constructors to instantiate it.

No. Constructor Description
1. public StringBuilder() Instantiates a StringBuilder with an initial capacity of 16.
2. public StringBuilder(int capacity) Instantiates a StringBuilder with the specified capacity.
3. public StringBuilder(CharSequence charsequence) Instantiates a StringBuilder with the contents of the specified CharSequence.
4. public StringBuilder(String myString) Instantiates a StringBuilder with the contents of the specified String.


StringBuilder sb=new StringBuilder();

Appending Items to a StringBuilder

Items can be added to a StringBuilder object using the append() method.


Chaining StringBuilder methods

Most of the methods in the StringBuilder return this so that the method calls can be chained together in a fluent manner.


How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:


What do You Think

Previous Post Next Post