Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
The following table lists the operators supported by the Java programming language.
All Operators Operator Use Description +
+op
Promotes op
toint
if it's abyte
,short
, orchar
-
-op
Arithmetically negates op
+
op1 + op2
Adds op1
andop2
; also used to concatenate strings-
op1 - op2
Subtracts op2
fromop1
*
op1 * op2
Multiplies op1
byop2
/
op1 / op2
Divides op1
byop2
%
op1 % op2
Computes the remainder of dividing op1
byop2
++
op++
Increments op
by 1; evaluates to the value ofop
before it was incremented++
++op
Increments op
by 1; evaluates to the value ofop
after it was incremented--
op--
Decrements op
by 1; evaluates to the value ofop
before it was decremented--
--op
Decrements op
by 1; evaluates to the value ofop
after it was decremented>
op1 > op2
Returns true
ifop1
is greater thanop2
>=
op1 >= op2
Returns true
ifop1
is greater than or equal toop2
<
op1 < op2
Returns true
ifop1
is less thanop2
<=
op1 <= op2
Returns true
ifop1
is less than or equal toop2
==
op1 == op2
Returns true
ifop1
andop2
are equal!=
op1 != op2
Returns true
ifop1
andop2
are not equal&&
op1 && op2
Returns true
ifop1
andop2
are bothtrue
; conditionally evaluatesop2
||
op1 || op2
Returns true
if eitherop1
orop2
istrue
; conditionally evaluatesop2
!
!op
Returns true
ifop
isfalse
&
op1 & op2
Returns true
ifop1
andop2
are both boolean and bothtrue
; always evaluatesop1
andop2
; if both operands are numbers, performs bitwiseAND
operation|
op1 | op2
Returns true
if bothop1
andop2
are boolean and eitherop1
orop2
istrue
; always evaluatesop1
andop2
; if both operands are numbers, performs bitwise inclusiveOR
operation^
op1 ^ op2
Returns true
ifop1
andop2
are different that is, if one or the other of the operands, but not both, istrue
<<
op1 << op2
Shifts bits of op1
left by distanceop2
; fills with0
bits on the right side>>
op1 >> op2
Shifts bits of op1
right by distanceop2
; fills with highest (sign) bit on the left side>>>
op1 >>> op2
Shifts bits of op1
right by distanceop2
; fills with0
bits on the left side&
op1 & op2
Bitwise AND
if both operands are numbers;
conditionalAND
if both operands are boolean|
op1 | op2
Bitwise OR
if both operands are numbers;
conditionalOR
if both operands are boolean^
op1 ^ op2
Bitwise exclusive OR
(XOR
)~
~op
Bitwise complement =
op1 = op2
Assigns the value of op2
toop1
+=
op1 += op2
Equivalent to op1 = op1 + op2
-=
op1 -= op2
Equivalent to op1 = op1 - op2
*=
op1 *= op2
Equivalent to op1 = op1 * op2
/=
op1 /= op2
Equivalent to op1 = op1 / op2
%=
op1 %= op2
Equivalent to op1 = op1 % op2
&=
op1 &= op2
Equivalent to op1 = op1 & op2
|=
op1 |= op2
Equivalent to op1 = op1 | op2
^=
op1 ^= op2
Equivalent to op1 = op1 ^ op2
<<=
op1 <<= op2
Equivalent to op1 = op1 << op2
>>=
op1 >>= op2
Equivalent to op1 = op1 >> op2
>>>=
op1 >>>= op2
Equivalent to op1 = op1 >>> op2
?:
op1 ? op2 : op3
If op1
istrue
, returnsop2
; otherwise, returnsop3
[]
See Creating and Using Arrays Used to declare arrays, to create arrays, and to access array elements .
See Using Objects Used to form long names (
params)
See Defining Methods Delimits a comma-separated list of parameters (
type)
(
type) op
Casts (converts) op
to the specified type; an exception is thrown if the type ofop
is incompatible with typenew
See Using Objects and Creating and Using Arrays Creates a new object or array instanceof
op1 instanceof op2
Returns true
ifop1
is an instance ofop2
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.