Chapter 8. Text and Core Utilities
If you’ve been reading this book sequentially, you’ve read all about the core Java language constructs, including the object-oriented aspects of the language and the use of threads. Now it’s time to shift gears and start talking about the Java application programming interface (API), the collection of classes that compose the standard Java packages and come with every Java implementation. Java’s core packages are one of its most distinguishing features. Many other object-oriented languages have similar features, but none has as extensive a set of standardized APIs and tools as Java does. This is both a reflection of and a reason for Java’s success.
Strings
We’ll start by taking a closer look at the Java String
class (or, more specifically, java.lang.String
). Because working with String
s is so fundamental, it’s important to understand how they are implemented and what you can do with them. A String
object encapsulates a sequence of Unicode characters. Internally, these characters are stored in a regular Java array, but the String
object guards this array jealously and gives you access to it only through its own API. This is to support the idea that String
s are immutable; once you create a String
object, you can’t change its value. Lots of operations on a String
object appear to change the characters or length of a string, but what they really do is return a new String
object that copies or internally references the needed characters of the original. ...
Get Learning Java, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.