5.5 The String Class and Its Methods
The developers of Java have formed a symbiosis between String as a class and String as a “built-in” data type. Compared to other objects, this special treatment for String is evident in two aspects:
-
The language allows the direct construction of String objects from String literals (strings in double quotes), such as "Dick Dastardly" .
-
The concatenation (of multiple strings with +, as in "Dick" + " " + "Dick Dastardly") is allowed, but the plus sign is not allowed for any other object type. For example, you can’t add up two Point objects. So, with the plus sign on String objects, a special operator is defined on the String class; user-defined overloaded operators aren’t possible in Java.
The String ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access