0

what is the difference between == ans equals

10th Aug 2016, 2:20 PM
srilekha
3 ответов
+ 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