"equals()" and "==" are both used for checking the equality of two variables.
A small difference is there though. - equals() checks for "value based equality" while "==" checks for reference equality.
- equals() is a method and can only be used in conjunction with an object while "==" is an operator and can be used for primitives and objects both
- equals() is a part of the Object class
- equals() can be overloaded and you can give your own meaning to it which is not possible with the "==" operator
- "==" when used with a primitive checks for the value help by the variables. On the other side when "==" is used with a reference variable it checks if the two reference variables point to the same object.
No comments:
Post a Comment