Strings

Lesson 9 of 20

Strings look simple but never change — learn their favorite methods and when StringBuilder saves the day.

The big picture

Text with superpowers

Strings are objects packed with helpers — and one big surprise: they can never be changed, only replaced.

Strings are objects

A String is a sequence of characters with built-in helpers: length(), charAt(i), equals(...).

Immutable

A String can never change — every "modification" builds a brand-new String.

StringBuilder changes

StringBuilder is the editable cousin — append, insert and reverse text in place.

equals, not ==

Compare text with s.equals(t); == compares references, not letters.