Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Handling character sequences is supported through three final classes: String, StringBuilder and StringBuffer. The Java 2 platform uses the variable-length UTF-16 encoding to store characters in char arrays and in the string handling classes. The UTF-16 encoding allows characters whose Unicode values are in the range 0000 to 10FFFF. The char type only represents Unicode values in the range 0000 to FFFF, i.e. characters that can be represented in a single 16-bit word. This means that the supplementary characters are represented by multiple char values, i.e. multiple 16-bit words, when these are stored in a string or a char array. The string handling classes provide methods to handle the full range of characters in the UTF-16 encoding, but we will not dwell on the subject in this book.
The String class implements immutable character strings, which are read-only once the string has been created and initialized, whereas the StringBuilder class implements dynamic character strings. The StringBuffer class is a thread-safe version of the StringBuilder class.