0

what is the difference between == ans equals

10th Aug 2016, 2:20 PM
srilekha
3 Answers
+ 2
Main difference betweenĀ ==Ā and equals in Java is thatĀ "=="Ā is used to compareĀ primitivesĀ whileĀ equals()Ā method is recommended to check equality of objects. Another difference between them is that, If bothĀ "=="Ā andĀ equals()Ā is used to compare objects thenĀ ==Ā returns true only if both references points to same object whileĀ equals()Ā can return true or false based on itsĀ overridden implementation. One of the popular cases isĀ comparing two String in JavaĀ in which case == and equals() method return different results.
10th Aug 2016, 2:55 PM
WPimpong
WPimpong - avatar
+ 1
please any example
10th Aug 2016, 2:51 PM
srilekha
- 1
== means that 2 objects are exactly the same . eqauls means the content is the same. Int are compared by = and strings fir example with equals.
10th Aug 2016, 2:44 PM
Eric Zeus
Eric Zeus - avatar