Relational Operators




The relational operators (comparison operators) give back a value of true or false (boolean). These operators are generally used with primitive data elements (int, double, boolean, ...). You should generally NOT use these operators to compare two objects (use the equals method or use the compareTo method).


==      is equal to
!=      is not equal to
<       is less than
<=      is less than or equal to
>       is greater than
>=      is greater than or equal to


Examples:

if (!(x>y)) ... if ( x>y && x>z) ... if (x<y || x<z) ... if (x > y) out.println("x is greater than y"); if (y > x) out.println("y is greater than x"); if (x > y && x > z) out.println("x is greater than y and z"); else if (y > z) out.println("y is greater than x and z"); else out.println("z is greater than x and y");