Case 1
string = string +((char)65) + 5;
everything is considered as String, but in the second case
The sequence of operations:
string +((char)65 = stringAstringA + 5 = stringA5
Case 2
string += ((char)65) + 5;
the first right side is calculated means that the first operation will look like ((char)65) + 5 , so the result is ((char)65) + 5 is 70 and after that + = operation.
The sequence of operations:
(char)65 + 5 = 70string + 70 = string70
Let's see another example
String string = "string"; string += ((char)65) + 5 + "A"; System.out.println(string);
Output string70A
Cause The same first right-hand side is calculated and the sequence of the operation being performed is performed.
(char)65 + 5 = 7070 + "A" = 70Astring + 70A = string70A
Ashish Aggarwal Dec 11 '13 at 9:57
source share