Showing posts with label Equality Operators. Show all posts
Showing posts with label Equality Operators. Show all posts

Java Equals Operators / Chapter -5/Operator & Assignments


java equals operators

Java Equals Operator


1. The result of Equality Operator is boolean either true or false.These are Equality operators in java.

= =, !=
 2.We can apply Equality Operators for primitive type and boolean type.
example:-
System.out.println(10==20) ;       output is             false
System.out.println(10!=20) ;        output is              true
System.out.println('a'=='b') ;      output is             false
System.out.println('a'==97) ;        output is              true
System.out.println(false==false) ;  output is            true

3. We can apply equality operator for objects.
If both references are pointing to the same object then equality operator returns true.
If both references are not pointing to the same object then equality operator returns false.
example:-
Test t1=new Test( );
Test t2=new Test( );
Test t3=t1;

                  System.out.println(t1==t2) ; output is false
System.out.println(t1==t3) ; output is true



Difference between Equality Operator and .equals( ) method



In java Equality operators( == , != )are meant for reference comparison(address comparison).
.equals( ) method is meant for content comparison .
example:-
String s1= new String("javabychetan");
String s2 =new String ("javabychetan");




        System.out.println(s1==s2) ;             output is false


        System.out.println(s1.equals(s2)) ;           output is true




Java - Equality Operators / Chapter -5/Operator & Assignments

1. The result of Equality Operator is boolean either true or false.These are Equality operators in java.

          = =, !=

 2.We can apply Equality Operators for primitive type and boolean type.

example:- 

System.out.println(10==20) ;       output is             false

System.out.println(10!=20) ;        output is              true

 System.out.println('a'=='b') ;      output is             false

System.out.println('a'==97) ;        output is              true

System.out.println(false==false) ;  output is            true

 

3. We can apply equality operator for objects.

If both references are pointing to the same object then equality operator returns true.

If both references are not  pointing to the same object then equality operator returns false.

 example:-

Flipkart End Of Season Sale






© Copyright 2017 Javabychetan.blogspot.com