In java, the ++ and ++ = operators can be used as character links in special context, in addition to the functions described earlier. So they are also called string operators, which have some interesting behaviors. If the expression starts with a string, all subsequent operands must be string type (the compiler automatically transmits the Character Sequence in double quotation marks to a string ):
Public class stringoperators {
Public static void main (string [] args ){
Int x = 0, y = 1, z = 2;
String s = "x, y, z ";
System. out. println (s + x + y + z );
System. out. println (x + "+ s );
S + = "(summed) = ";
System. out. println (s + (x + y + z ));
System. out. println ("" + x );
}
}
Output
X, y, z 012
0 x, y, z
X, y, z (summed) = 3
0
It should be noted that the first line outputs 012 rather than sum 3, because the compiler automatically converts them into the string form, and the last part appends a string to s with ++ =, and use parentheses to control the compiler conversion so that they can sum smoothly.