Java Reference
In-Depth Information
In Java, the symbol == , which consists of two equal signs, is called the equality operator.
Recall that the symbol = is called the assignment operator. The equality operator, == ,
determines whether two expressions are equal, whereas the assignment operator, = ,
assigns the value of an expression to a variable.
Each of the relational operators is a binary operator; that is, it requires two operands.
Because the result of a comparison is true or false , expressions using these operators
evaluate to true or false .
4
Relational Operators and Primitive Data Types
You can use the relational operators with integral and floating-point primitive data types.
For example, the following expressions use both integers and floating-point numbers:
Expression
Meaning
Value
8 < 15
8 is less than 15
true
6 != 6
6 is not equal to 6
false
2.5 > 5.8
2.5 is greater than 5.8
false
5.9 <= 7.5
5.9 is less than or equal to 7.5
true
For char values, whether an expression using relational operators evaluates to true or
false depends on the collating sequence of the Unicode character set. Table 4-2 gives
the collating sequence (Unicode value as a decimal integer) of some of the characters in
the character set.
TABLE 4-2 Some Characters of the Unicode Character Set and their Unicode Value as a
Decimal Integer
Unicode
Value
Unicode
Value
Unicode
Value
Unicode
Value
Character
Character
Character
Character
' '
=
Q
i
32
61
81
105
!
>
R
j
33
62
82
106
"
A
S
k
34
65
83
107
*
B
T
l
42
66
84
108
43
+
C
U
67
85
109
m
-
D
V
n
45
68
86
110
/
E
W
o
47
69
111
87
X
48
0
70
F
88
112
p
 
 
Search WWH ::




Custom Search