Since ++ is a unary operator, ++ is interpreted as follows:
"R"+ represents the string concatenation, and then the second argument (to calculate the concatenation)+'a' represents the explicit setting of the ( + ) sign for the (numeric) char literal 'a' . Since you have explicitly set the sign of the value, it is treated as a number, and therefore the result +'a' is the number representation of the character 'a' , and therefore the result is R97 .
Similarly, if you did String a = "R"+ -'a'; , then the numerical value of 'a' (which is 97 ) will be canceled, and the result will be R-97 .
If, however, you simply ignored the + sign in front of 'a ', then 'a' considered as a character, not as a number, and the result would be Ra .
source share