Java - Compare the Objects using equals() & hashCode()

  Рет қаралды 44,133

Coding Simplified

Coding Simplified

Күн бұрын

Source Code:thecodingsimplified.com/compa...
- By default equals method only compare the reference object
- To compare based on Object value, override the equals & hashcode method
- First compare by hashcode(), if hashCode of both Objects are different, then objects are not equal
- but if hashcode of both Objects are same, then we check the equals method
- hashcode is used to quickly checl the equality
- Now whenever you're adding Object in Set or Map, then also you need to overide the equals & hashcode
- Because, Set & Map check the equality & if Object are equal it won't add again so you need to add equality
CHECK OUT CODING SIMPLIFIED
/ codingsimplified
★☆★ VIEW THE BLOG POST: ★☆★
thecodingsimplified.com
I started my KZbin channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 400+ videos.
★☆★ SUBSCRIBE TO ME ON KZbin: ★☆★
kzbin.info...
★☆★ Send us mail at: ★☆★
Email: thecodingsimplified@gmail.com

Пікірлер: 77
@samirpanchal9266
@samirpanchal9266 2 жыл бұрын
Great explanation, I was scratching my head from last 2 hours and your 16 min video made it clear easier than books and Udemy courses. Keep it up, man.
@CodingSimplified
@CodingSimplified 2 жыл бұрын
Thanks Samir for your nice feedback. Keep Watching our other videos as well.
@naveenprasanth1233
@naveenprasanth1233 Жыл бұрын
== compares reference and .equals compares the values is what I learnt
@sujithkumar3925
@sujithkumar3925 3 жыл бұрын
thankyou you cleared all my doubts in this concept, thanks a lot :))
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@iamsh4r106
@iamsh4r106 2 жыл бұрын
Great video, really helped me grasp the concepts. I have question, is it a good idea to put the hashCode equality check inside of the equals method?
@CodingSimplified
@CodingSimplified 2 жыл бұрын
Either is fine. We can have another function as well for it to make it more modular.
@nurbekhalikulov8867
@nurbekhalikulov8867 Жыл бұрын
Thank you very much dude. Your explanation is so neat and objective. Kudos on you
@CodingSimplified
@CodingSimplified Жыл бұрын
Glad it was helpful! Keep Watching.
@larbiaitdjebara1683
@larbiaitdjebara1683 2 жыл бұрын
Thank you so much for the tutorial it was really well explained, although i wish you explained a little bit more the casting part " Employee emp = (Employee) obj ", but other than that great video !
@techieadi4377
@techieadi4377 Жыл бұрын
sir, you stop making videos ?? your video is very good for fresher as well as experienced people especially those who want to learn Dynamic programming what great content you have sir. And the very important thing which I want to thank you that you have created these videos 2 years before only when no one was giving this imp concept for free and you gave. Thank you sir
@CodingSimplified
@CodingSimplified Жыл бұрын
Thanks Adi for your such feedback. It really gives nice feeling to hear such feedback. Due to my workload, I was not getting much time to create videos. But now, I'm thinking to start creating videos again. All your words have provided much motivation to me to start again. Stay tuned. You'll see more videos now.
@techieadi4377
@techieadi4377 Жыл бұрын
@@CodingSimplified yes sir please I am eagerly waiting for the videos please make the videos on programming sir on "collection" because it is the heart of java and no one gives much clarity on that so please make some videos on the "collection" side and their programs.
@markthomas9641
@markthomas9641 2 жыл бұрын
Great video. Alternatively if you are comparing JSON then DeltaJSON is a really useful set of tools for compare, merge and graft.
@CodingSimplified
@CodingSimplified 2 жыл бұрын
Thanks for your nice feedback.
@academico4891
@academico4891 2 жыл бұрын
thanks a lot dude it's just what I was looking for :)
@CodingSimplified
@CodingSimplified 2 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@abirkec
@abirkec 3 жыл бұрын
Very nice explanation actually. 16 mins worth it. Thank you lot
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@e.ch.vidyasagarkorada8937
@e.ch.vidyasagarkorada8937 4 жыл бұрын
Thank you for knowledge Very useful I have one dout What happens if we override only equals method not overriding hash code In case map is it will consider Both objects are equal or not Should we override both methods or is it mandatory to check for equality Please reply Thanks advance
@CodingSimplified
@CodingSimplified 4 жыл бұрын
Hash code is used to improve searching. As we explained in video, even if you've only equals, it'll work, but if you override Hashcode, it'll do 1st check & if Hashcode is equal then only check for equals. Let me know if you further doubts.
@SHAnkarKumar-go4xk
@SHAnkarKumar-go4xk Жыл бұрын
To override the hashcode is that the only way or do we have any other way to check the hashcode values of two objects?
@shubhamgagre8789
@shubhamgagre8789 Жыл бұрын
Nice explanation To the point Exactly what I was looking for
@ANJALISingh-cq6nt
@ANJALISingh-cq6nt Жыл бұрын
great explanation sir Thank u so much sir
@CodingSimplified
@CodingSimplified Жыл бұрын
Thanks Anjali for your nice feedback.
@shynimol4454
@shynimol4454 2 жыл бұрын
great explanation..Simple and not at all confusing
@CodingSimplified
@CodingSimplified 2 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@brandyplays6134
@brandyplays6134 4 жыл бұрын
beautifully explained..thank you so much:)
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@pawankapure7593
@pawankapure7593 3 жыл бұрын
Thank you.. Nicely Explained
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@abhinavminocha1894
@abhinavminocha1894 4 жыл бұрын
Sir please upload more videos on Strings, Graphs and Dynamic Programming. Thanks so much in advance.
@CodingSimplified
@CodingSimplified 4 жыл бұрын
Sure, will upload on these topics.
@namrathas5804
@namrathas5804 Жыл бұрын
Very well explained. spot on explanation. Thank you so much for this video
@CodingSimplified
@CodingSimplified Жыл бұрын
Thanks for your nice feedback. Keep Watching :)
@annapureddyravi4054
@annapureddyravi4054 2 жыл бұрын
Very nice explanation..thanks sir
@somyarathee
@somyarathee 3 жыл бұрын
SUPEERR!! Thank u soo much sir!!!
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@FTLC
@FTLC Жыл бұрын
thanks for such a great explanation
@saimamalim9861
@saimamalim9861 Жыл бұрын
Great explanation
@ajaysingh9570
@ajaysingh9570 2 жыл бұрын
such a wonderful explanation ..
@CodingSimplified
@CodingSimplified 2 жыл бұрын
Thanks for your nice feedback.
@atharvakale5842
@atharvakale5842 2 жыл бұрын
Great Explanation man
@pnworks9186
@pnworks9186 Жыл бұрын
Very helpful Sir
@CodeMode9313
@CodeMode9313 Жыл бұрын
bhai well explained ...keep it up
@harikagoud7652
@harikagoud7652 2 жыл бұрын
do you mean equals() and hashcode() exists only for set and map but not for list?
@13success66
@13success66 2 жыл бұрын
Very nice explanation
@shubhamdeshmukh1866
@shubhamdeshmukh1866 2 жыл бұрын
Broooo u saved me 🙌🙌🙌🙌🙌🙌
@adityalodhi4023
@adityalodhi4023 Жыл бұрын
God level explanation.....but after watching it I have one doubt if e1 and e2 have same content and we are overriding only equals method then it will never calls equals method bcoz their hashcode is different according to the object class hashcode method.then it will add e1 and e2 in hashset even though their content is same......plz reply
@adityalodhi4023
@adityalodhi4023 Жыл бұрын
2nd doubt- I m overriding hashcode method e1 and e2 has same hashcode and i m not overriding equals then it should simply discard the e2 object bcoz their hashcode is same but it is adding in hashset........now if hashcode is same for e1 and e2 then it is calling object class equals method or not????? For content checking plz reply
@SACHIN-gd6zy
@SACHIN-gd6zy 3 жыл бұрын
Very good explanantion.
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@arlingamnandini1327
@arlingamnandini1327 3 жыл бұрын
Thank u so much....
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@meenaxichaudhary1721
@meenaxichaudhary1721 3 жыл бұрын
awesome explaination
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@sreenivaskp4181
@sreenivaskp4181 3 жыл бұрын
Excellent Video 👌👌👏👏
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@sagardarade
@sagardarade 3 жыл бұрын
Crystal clear
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@ajitbombe5168
@ajitbombe5168 3 жыл бұрын
Thanks :)
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@karthickn956
@karthickn956 Жыл бұрын
Thanks dude
@xahmiyuto7844
@xahmiyuto7844 2 жыл бұрын
ty
@kiranking5717
@kiranking5717 3 жыл бұрын
Excellent
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@adityapatil3884
@adityapatil3884 3 жыл бұрын
Best explanation
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@muzammilkhan382
@muzammilkhan382 Жыл бұрын
thankyou sir
@kvnagendra5354
@kvnagendra5354 Жыл бұрын
❤❤❤
@user-kh6rp6yx1j
@user-kh6rp6yx1j Ай бұрын
Hey man.
@ramesh_hegde
@ramesh_hegde 2 жыл бұрын
return this.name.length() % 10 will return 7 for both words with length 7 and 17 right?
@PomogB
@PomogB Жыл бұрын
Indian English is wonderful
@umeshjoshi8047
@umeshjoshi8047 2 жыл бұрын
Great explanation
@CodingSimplified
@CodingSimplified 2 жыл бұрын
Thanks for your nice feedback. Keep Watching.
@shraddhadethe7644
@shraddhadethe7644 3 жыл бұрын
Best explanation
@CodingSimplified
@CodingSimplified 3 жыл бұрын
Thanks for your nice feedback. Keep Watching.
Java - Sort the Object array or Object List
14:29
Coding Simplified
Рет қаралды 26 М.
.equals() vs. == in Java - The Real Difference
8:48
Coding with John
Рет қаралды 182 М.
路飞被小孩吓到了#海贼王#路飞
00:41
路飞与唐舞桐
Рет қаралды 82 МЛН
39kgのガリガリが踊る絵文字ダンス/39kg boney emoji dance#dance #ダンス #にんげんっていいな
00:16
💀Skeleton Ninja🥷【にんげんっていいなチャンネル】
Рет қаралды 8 МЛН
Who has won ?? 😀 #shortvideo #lizzyisaeva
00:24
Lizzy Isaeva
Рет қаралды 65 МЛН
Overriding equals and hashCode in Java - 039
6:30
Deege
Рет қаралды 82 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
The Absolute Best Intro to Monads For Software Engineers
15:12
Studying With Alex
Рет қаралды 611 М.
02. Equals and HashCode Contract & Different Variations
11:19
WebEncyclop Tutorials
Рет қаралды 53 М.
Java Strings are Immutable - Here's What That Actually Means
7:06
Coding with John
Рет қаралды 608 М.
PHP doesn't suck (anymore)
10:48
Aaron Francis
Рет қаралды 201 М.
路飞被小孩吓到了#海贼王#路飞
00:41
路飞与唐舞桐
Рет қаралды 82 МЛН