4.2 Relational Operators

The relational operator determine the relationship that one operand has to the other. Specifically, they determine equality and ordering. Table 4.2 shows relational operators.

Table 4.2 Relational Operators

The outcome of these operations is a boolean value. The relational operators are most frequently used in the expressions that control the if statement and the various loop statements.

Any type in Java, including integers, floating-point numbers, characters, and Boolean can be compared using the equality test, = =, and the inequality test, !=. Notice that in Java equality is denoted with two equal signs, not one. ( single equal sign is the assignment operator.)

eg:

   int a = 4;
   int b = 1;
   boolean c = a < b;

In this case, the result of a < b (which is false) is stored in c.