4.2. Mutable strings: StringBuilder

[9.1] Manipulate data using the StringBuilder class and its methods

The class StringBuilder is defined in the package java.lang, and it has a mutable sequence of characters. You should use the class StringBuilder when you’re dealing with larger strings or modifying the contents of a string often. Doing so will improve the performance of your code. Unlike StringBuilder, the String class has an immutable sequence of characters. Every time you modify a string that’s represented by the String class, your code creates new String objects instead of modifying the existing one.

Exam Tip

You can expect questions on the need for the StringBuilder class and its comparison with the String ...

Get OCA Java SE 8 Programmer I Certification Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.