Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Difference Between == and equals method in Java with Example : Core Java Interview Question

Difference between == and equals method is not one of the most frequently asked question in java developer interview. We need to understand the concept of equals()  method and == operator in java.
In other words ,

Example 1:


Integer i = new Integer(10);
Integer j = i;

in the above code, i == j is true because both i and j refer to the same object.

Example 2:


Integer i = new Integer(10);
Integer j = new Integer(10);

In the above code, i == j is false because, although they both have the value 10, they are two different objects.


That's it for today, please mention in comments if you have any questions regarding difference between == and equals() method in java.


This post first appeared on Java Hungry, please read the originial post: here

Share the post

Difference Between == and equals method in Java with Example : Core Java Interview Question

×

Subscribe to Java Hungry

Get updates delivered right to your inbox!

Thank you for your subscription

×