Operator
- Separator: ,; [] ()
- Arithmetic operator: +-*/% + +--
- Relational operators: > < >= <= = = =!
- Logical operator: ! & | ^ && | |
- Assignment operator: =
- Extended assignment Operator: + = = *=/=
- Trinocular operator: ?:
- String Join operator: +
The "+" and "-" operators can also be used as positive and negative symbols of the data.
&&: Short circuit and, as long as one of the expressions or methods has a value of false, the result is false and the subsequent operation is not performed.
|| : Short-circuiting or, as long as one of the expressions or methods has a value of true, the result is true and the subsequent operation is not performed.
Short s = ten; // error, S is short,1 default to int, first convert right s to int and add, result int // s = s + 1; // error s = (short) (s + 1); // correct s + = 1; // correct, equal to S = (short) (S + 1);
Three-mesh operators:
X? Y:z x is a Boolean type, and if X is true, the expression result is Y, otherwise Z
String connector: As long as "+" appears on either side of the string, "+" represents the string connector
- The operator "+" is used for numeric type data, which is an addition operator
Example: "Abd" + "de" Result: "ABCDE"
- Used for string Lee type, which is a connector
- string + numeric value, Java automatically converts the value to a string and then joins it into a new string
Example: "12" + 34 Result: "1234"
System.out.println (12+34+ ""); // " the" System.out.println ("+12+34"); // "1234"
Precedence of Operators
- In addition to the Monocular operator, assignment operator, and conditional operator, the other operators are combined from left to right.
- Operator Precedence formula: non-, count, close, and OR, assign
- The following table is priority order, high priority in upper, same row priority
Operator Precedence Upgrade
Operator description |
Java operators |
Separator |
. [] () , ; |
Monocular operator |
+-~! + +-- |
Create or type conversions |
New (Type) |
Multiplication/Division |
* / % |
Addition/Subtraction |
+ |
Relationship |
< <= >= > instanceof |
Equivalent |
= = = |
Bitwise-AND |
& |
Bitwise XOR OR |
^ |
Bitwise OR |
| |
Conditions and |
&& |
Conditions or |
|| |
Conditions |
? : |
Assign value |
= |
Java Learning: Operators and Precedence