Lesson 2 of 912 minModule progress 0%

Module 9: Advanced Core Features

StringBuilder vs StringBuffer

Pick the correct mutable string class for single-threaded or synchronized scenarios.

StringBuilder is unsynchronized and ideal for local operations.

StringBuffer synchronizes methods and may be necessary when multiple threads share an instance.

Prefer returning immutable Strings from APIs even if constructed with builders internally.

Advertisement

Lesson check

Why is StringBuilder usually faster than StringBuffer?

Next lesson →