Special Operator Support for Strings
Before leaving the subject of operators, it is important to cover a special use of the addition operator as it relates to the String class discussed later in Chapter 8, "Using Strings and Text."
In general, Java, unlike C++, does not support operator overloading. There is one exception, however. Java does allow the concatenation of String objects using the + and += operators. The behavior of these operators with String objects is just what you would expect if you are familiar with C++. The String operands are concatenated to produce a new String that contains the values of both. In the following expression, the resulting string would be "Hello World":
"Hello" + " World"
If one of the operands used with ...
Get Special Edition Using Java 2 Standard 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.