Java Tutorial · Revision notes
Java Strings
A String in Java is an immutable sequence of characters stored as an object. This chapter covers creating strings, the most-used String methods, the mutable StringBuffer and StringBuilder classes, and the String constant pool that decides when == is true.
Quick revision
- String is final and immutable; methods return new strings
- Use equals() for content; == compares references
- substring(begin, end) excludes end; indexOf returns -1 when absent
- StringBuilder: fast, not thread-safe. StringBuffer: synchronized
- Literals share one pooled object; new String always creates a new one
- intern() returns the pooled string