Sorting using Comparator | Comparable Vs Comparator | Java interview question | Java collections

preview_player
Показать описание
In this video, we will go through the java comparator interface.

The difference between comparable and comparator in java is always a question to prepare for. It’s one of the very popular java interview questions.

Before you guys move on with this video make sure you have already gone through my java sorting series. Hit the below link to learn the java comparable and the comparator concept from the scratch.

So we use a comparator for the customize sorting. Assume that you get a requirement to sort String class object in some order. You can’t change the String class source code. Hense to provide your own customize sorting logic you will be writing your comparator class by implementing an interface called comparator and overriding the compare() method. So the compare method is where we need to define our sorting logic. It’s similar to compareTo() of java Comparable interface.

You can use this video if you are preparing for a java interview and particularly if you are looking for some java collection interview question.

Ok, here is some final take away.

To sort a collection in a customized way, we need a Comparator interface.
The key method we discussed in this video compares() method of Comparator interface.

#ComparableVsComparator #JavaInterview #JavaCollections

For more videos in Collection framework, consider subscribing by clicking the link below.

Stay tuned and like my Facebook page for more.

Music :
-----------
credits : -
(intro)
Creative Commons — Attribution 3.0 Unported— CC BY 3.0

intro template :
Рекомендации по теме
Комментарии
Автор

You are in the process of making good IT professionals....do continue and thanks for all your efforts

vikasht
Автор

I had been searching for this level of content on comparators for solving my long struck codeforces problems. I finally got this after searching 10-15 channels. Thank you brother.

dhruvsaini
Автор

This is such an amazing series. Thank you SO MUCH. I was having a bit of trouble grasping this topic but you explained it absolutely phenomenally. Please keep doing what you're doing, you're definitely making a difference!

Starchaser_
Автор

Super bro you are.. really easy to understand.. Please don't stop teaching.

ashwinrajanta
Автор

You added a lot of extra context to help reinforce the material. The text is really easy to see and the concepts are explained clearly. Thanks for all your hard work!

InSterquiliniisInvenitur
Автор

Just finished the entire playlist in a few hours. Thank you for your valuable content. Your lectures kept me hooked to your playlist and honestly, there was so much information. Keep uploading!😀

kritisingh
Автор

Sir this is AMAZING, I like the way you are doing, when you started giving an example for Song class, then you started your implementation. Thank you so much I am so happy we have you here in YouTube

Adam-gpij
Автор

Thank you Abhilash for putting such a wonderful contents about comparable and comparator.

shameemahamad
Автор

Your explanation skills are mindblowing

nikhildabhade
Автор

as usual you teach just amaze us;
accidently i put " ; " instead of " . "

prakashpandey
Автор

You really nailed this sorting topic. Finally I got the understanding. Thank you so much!!!

suseesenthil
Автор

Top Software Engineer top teacher Only love from greece

spyrostomaras
Автор

i watched durga soft video and i gain some knowledge and idea but form your videos i learned a lot which missed by Durga soft video, i got more clear cut and deep concept, thank u so much sir, plz keep going on and make some more videos like this

khagendrakumarmajhi
Автор

This is so good that I have come across. Quality of teaching is superb. Thank you so much sir

jakeg
Автор

thank you so much for explaining these concepts, I enjoyed your lectures thoroughly and learned a lot. please keep posting such content for us beginners. thanks again.

hussainrizvi
Автор

Your content is very unique and content has in depth knowledge. I can understand very hard concept very easily. I want to request you to make tutorial on Spring Boot and java webservices.Thanks you very much for your work.It's helps me very much

didarulamin
Автор

This was very well broken down. Thank you for this video.

onjelbercier
Автор

awesome tutorial! I now clearly understand comparable and comparator! Keep doing more videos! More power to you! Thank you, sir! :)

prahladsravz
Автор

Thanks Abhilash for such wonderful video deeply explained. Am trying in java so your all videos are valuable to me.

niranjanpadhi
Автор

Your videos are amazing.. Please keep posting more.

rb