Java Reference
In-Depth Information
except that var is evaluated only once. This means that op = is valid only
if op is valid for the types involved. You cannot, for example, use <<= on
a double variable because you cannot use << on a double value.
Note the parentheses used in the expanded form you just saw. The ex-
pression
a *= b + 1
is analogous to
a = a * (b + 1)
and not to
a = a * b + 1
Although a+= 1 is the same as ++a and a++ , using ++ is considered idio-
matic and is preferred.
Exercise 9.3 : Review your solution to Exercise 7.3 to see if it can
be written more clearly or succinctly with the operators you've learned
about in this chapter.
9.2.8. String Concatenation Operator
You can use + to concatenate two strings. Here is an example:
String boo = "boo";
String cry = boo + "hoo";
cry += "!";
System.out.println(cry);
 
Search WWH ::




Custom Search