Precedence Operator Description Association
1 ++, -- Postincrement, Postdecrement R-> L
2 ++, -- Preincrement, Predecrement R-> L
+,-Unary plus, unary minus R-> L
~ Bitwise compliment R-> L
! Boolean not r-> L
3 new Create object R-> L
(Type) Type cast R-> L
4 *,/, % Multiplication, division, remainder L-> R
5 +,-Addition, subtraction L-> R
+ String concatenation L-> R
6 <, >>>>>> Left shift, right shift, unsigned right shift L-> R
7 <, <=,>,> = L-> R
Instanceof Type comparison L-> R
8 = ,! = Value equality and inequality L-> R
= ,! = Reference equality and inequality L-> R
9 & Boolean and l-> R
& Bitwise and l-> R
10 ^ Boolean xor l-> R
^ Bitwise xor l-> R
11 | Boolean or l-> R
| Bitwise or l-> R
12 & Conditional and l-> R
13 | Conditional or l-> R
14? : Conditional Ternary Operator L-> R
15 =, + =,-=, Assignment Operators R-> L
* =,/=, % =,
& =, ^ =, | =,
<=, >>=,
>>>=
Operator Precedence Group Associativity Operator Precedence
(), [], Postfix ++, postfix -- left Highest
Unary +, unary-, prefix ++, prefix --,~, ! Right
(Type), new left
*,/, % Left
+,-Left
<, >>>>> Left
<, <=,>, >=, Instanceof
= ,! =
& Left
^ Left
| Left
& Left
| Left
? : Left
=, + =,-=, * =,/=, % =, <=, >>=, >>>=, & =, |=, ^ = Right lowest
Simple plus sign operation
Public class MainClass {
Public static void main (String [] arg ){
Int count = 1;
Count + = 5;
System. out. println (count );
Count = count + 5;
System. out. println (count );
}
}
Conditional operation and comma operator
If (value> conditionValue ){
Result = result1;
} Else {
Result = result2;
}
Logical_expression? Expression1: expression2
Public class MainClass {
Public static void main (String [] args ){
Int v = 1;
System. out. println (v = 1? "A": "B ");
V ++;
System. out. println (v = 1? "A": "B ");
}
}