15.20.2
Boolean Equality Operators
==
and
!=
EXPRESSIONS
The value produced by the
==
operator is
true
if the value of the left hand
operand is equal to the value of the right hand operand; otherwise, the result is
false
.
The value produced by the
!=
operator is
true
if the value of the left hand
operand is not equal to the value of the right hand operand; otherwise, the
result is
false
.
15.20.2 Boolean Equality Operators
==
and
!=
If the operands of an equality operator are both of type
boolean
, then the opera
tion is boolean equality. The
boolean
equality operators are associative.
The result of
==
is
true
if the operands are both
true
or both
false
; other
wise, the result is
false
.
The result of
!=
is
false
if the operands are both
true
or both
false
; other
wise, the result is
true
. Thus
!=
behaves the same as
^
( 15.21.2) when applied
to boolean operands.
15.20.3 Reference Equality Operators
==
and
!=
Things are more like they are now than they ever were before.
Dwight D. Eisenhower
If the operands of an equality operator are both of either reference type or the null
type, then the operation is object equality.
A compile time error occurs if it is impossible to convert the type of either
operand to the type of the other by a casting conversion ( 5.4). The run time val
ues of the two operands would necessarily be unequal.
At run time, the result of
==
is
true
if the operand values are both
null
or
both refer to the same object or array; otherwise, the result is
false
.
The result of
!=
is
false
if the operand values are both
null
or both refer to
the same object or array; otherwise, the result is
true
.
While
==
may be used to compare references of type
String
, such an equal
ity test determines whether or not the two operands refer to the same
String
object. The result is
false
if the operands are distinct
String
objects, even if
they contain the same sequence of characters. The contents of two strings
s
and
t
can be tested for equality by the method invocation
s.equals(t)
( 20.12.9). See
also 3.10.5 and 20.12.47.
364
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved