Saturday, October 15, 2016

Equals vs ==

1. == Is used to compare reference and equals is used to compare the contents.

2. == We can used with primitive type, when we used == with primitive types(data types) it will work as comparing two values. But equals we can not used for primitives type as it is method declared in object class. In short all the classes in java having own equals method.

3. If we call equals on reference variable who have null value, then we will get nullpointerexception.
Example
String s;
S.equals("Abc")
It will throw nullpointerexception.

4. Equals is a method which is in object class. Object class is extended by all the classes in java. So in short equals method is contained by all the classes in java.

No comments:

Post a Comment

உப்பு மாங்காய்

சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...