Originally posted by kumar abhay:
i have a question regarding string precedence given below:
string x="my name is jitender kumar"
sir i want to ask that due to associativity ,the (=)sign starts functioning from RIGHT SIDE but in the string ,it starts executing from left.
it is really confusing,either to use index method in string ,even then,it starts counting from left rather than from right.for me this is a great confusion.
You're right. indexOf() in the String class counts from left to right. Some Java
operators, including the '=', are right associative. That's just the way it is. You'll have to take your questions up with the creators of Java as to
why they made it that way. It won't change, so you will just have to learn which operators are right associative to be able to code Java properly. Here are some more:
'++', '--' (when used as pre-increment operators)
'~', '!', '-'(arithmetic negation), '+'(opposite of the previous operator, not additive)
'?:' (conditional operator)
'=', '*=', '/=', '%=', '+=', '-=', and other assignment operators.