Tuesday, 29 July 2014

Difference between x.equal(y) and x==y

The equal and == operator are used to compersion check and both are returning the Boolean value(true or false)

For value type both of them are working same.
 int a= 10;
int b= 10;
if(a==b) // true;
if(a.equal(b)) // true

But for reference type both of them are behaving different.

StringBuilder sb1 = new StringBuilder(“Value”);
StringBuilder sb2 = new StringBuilder(“Value”);
If(sb1 == sb2) // false
If(sb1.equal(sb2)) // true

No comments:

Post a Comment