Site icon Narayana Tutorial

Equality Operator

Equality Operator (= =), (!)

We can apply equality operators for all primitive data types including boolean also.

We can apply equality operators even for object reference also ‘ r1 = = r2 ‘ is true if and only if both are pointing to same object.

If we won’t to apply = = operator there should be some relationship  b/n the argument type otherwise we will get compile time error.

—> in comparable types thread, exception.

—> consider the following types.

Que:- Which of the following expressions are valid ?

  1. o1 = = s 1
  2. o1 = = s 2
  3. s 1 = = s 2 ( compile time error)
  4. All the above

Ans:- 1, 2 .

For any Object reference r , ” r = = null ” is always false.

Note:-
In general ” = = ” operator always meant for reference comparison. Where as equals ( ) method for content comparison.