0Pricing
Java Academy · Lesson

Building Strings with StringBuilder

Efficient concatenation.

A Mutable String Builder

StringBuilder is a mutable sequence of characters. Unlike String, you can change its contents in place, which makes building text efficient.

Creating a StringBuilder

Create one with new StringBuilder() for an empty builder, or pass initial text to start with content.

public class Main {
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();
        StringBuilder named = new StringBuilder("Hello");
        System.out.println("empty length: " + sb.length());
        System.out.println("named: " + named);
    }
}

All lessons in this course

  1. Why Strings Are Immutable
  2. Building Strings with StringBuilder
  3. StringBuilder Methods
  4. StringBuilder vs StringBuffer
← Back to Java Academy