Java Reference
In-Depth Information
4.2.2. Integer Operations
The Java programming language provides a number of operators that act on integral values:
• The comparison operators, which result in a value of type boolean :
♦ The numerical comparison operators < , <= , > , and >= 15.20.1 )
♦ The numerical equality operators == and != 15.21.1 )
• The numerical operators, which result in a value of type int or long :
♦ The unary plus and minus operators + and - 15.15.3 , § 15.15.4 )
♦ The multiplicative operators * , / , and % 15.17 )
♦ The additive operators + and - 15.18 )
♦ The increment operator ++ , both prefix (§ 15.15.1 ) and postfix (§ 15.14.2 )
♦ The decrement operator -- , both prefix (§ 15.15.2 ) and postfix (§ 15.14.3 )
♦ The signed and unsigned shift operators << , >> , and >>> 15.19 )
♦ The bitwise complement operator ~ 15.15.5 )
♦ The integer bitwise operators & , ^ , and | 15.22.1 )
• The conditional operator ? : 15.25 )
• The cast operator (§ 15.16 ) , which can convert from an integral value to a value of
any specified numeric type
• The string concatenation operator + 15.18.1 ) , which, when given a String operand
and an integral operand, will convert the integral operand to a String representing
its value in decimal form, and then produce a newly created String that is the con-
catenation of the two strings
Other useful constructors, methods, and constants are predefined in the classes Byte , Short ,
Integer , Long , and Character .
If an integer operator other than a shift operator has at least one operand of type long , then
the operation is carried out using 64-bit precision, and the result of the numerical operator
is of type long . If the other operand is not long , it is first widened (§ 5.1.5 ) to type long by
numeric promotion (§ 5.6 ) .
Otherwise, the operation is carried out using 32-bit precision, and the result of the numer-
ical operator is of type int . If either operand is not an int , it is first widened to type int by
numeric promotion.
Search WWH ::




Custom Search