Java operator Reference Manual

Source: Internet
Author: User

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 ");
  }
}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.