Interview Question | Comparable vs Comparator in Java

  Рет қаралды 639,727

Telusko

Telusko

6 жыл бұрын

Spring and Microservices Live Course : bit.ly/springmslive
Coupon: TELUSKO25 (25% Discount)
Industry-Ready Java Spring Microservices Developer Live : bit.ly/JavaMS2
Complete Java Developer Course : bit.ly/Comp-Java-Dev-2
Coupon: TELUSKO20 (20% Discount)
For More Queries WhatsApp or Call on : +919008963671
website : courses.telusko.com/
Instagram : / navinreddyofficial
Linkedin : / navinreddy20
TELUSKO Android App : bit.ly/TeluskoApp
Discord : / discord
In this video we will see :
- Comparator and Comparable in Java
- Difference between Comparator and Comparable
- Example of Comparator and Comparable
- Create getters and setters
- toString() method
- Creating List and adding values in List
- Collection.sort method to sort the List
- When to use Comparable and when to use Comparator
- compareTo() method
- How to use comparable
- How to use Comparator
#java #interview
Java and Spring Framework For beginners with Spring Boot : - bit.ly/3LDMj8D
Java Tutorial for Beginners (2023) :- bit.ly/3yARVbN
Editing Monitors :
amzn.to/2RfKWgL
amzn.to/2Q665JW
amzn.to/2OUP21a.
Subscribe to our other channel:
Navin Reddy : kzbin.info/door/xmk...
Telusko Hindi :
kzbin.info/door/itz...
Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
www.telusko.com/contactus

Пікірлер: 366
@raragam
@raragam 4 жыл бұрын
This guy is simply amazing. Hats off to his teaching abilities !!
@saby8765
@saby8765 6 жыл бұрын
Perfect... 1. for known datatypes like String, Int the classes have already implemented Comparable, so you don't need to bother about it. 2. For your own Objects you need to implement Comparable to make the sort() work, which is basically mimicking the strategy for point 1. 3. If you want to change your sort logic implemented by your Comparable interface you need to use Comparator, for either known datatypes or your own classes. 4. You can make the sort() for your own classes work if you implment Comparator interface, whether you have implamanted Comparable or not.
@naksnaz
@naksnaz 4 жыл бұрын
​@@AK-rx5yp : I have on doubt when we can write our own logic with compare To() method if we are implementing Comparable why should we use Comparator interface?
@sathyalalithanjaliavadhanu835
@sathyalalithanjaliavadhanu835 4 жыл бұрын
What is difference between comparable and comparator
@showdank
@showdank 4 жыл бұрын
@@naksnaz using comparable you can give only one logic and its locked.. Locked meaning you have given that one logic to sort in your class which implements comparable. In this case sort by RAM. comparator comes handy when you have sort by multiple fields. You can use comparator to sort by BRAND and then again use that result to sort by PRICE. Basically to have multiple sorting. Which is not possible using comparable.
@altamashalisheikh
@altamashalisheikh 3 жыл бұрын
@@naksnaz change default sort() work, means by default it's sorted by ram if want to sorted by other parameter need to use comprator.
@altamashalisheikh
@altamashalisheikh 3 жыл бұрын
@@sathyalalithanjaliavadhanu835 comparable interface basically work for sort objects by default parameter bt using comparator we can sort objects according to our choice parameter.
@steviet5246
@steviet5246 5 жыл бұрын
I'm here to learn for my exams, nobody explained it so simple like you thanks!
@axeedo
@axeedo 5 жыл бұрын
Wow! Just wow man! You are the MVP! There is no other place on the internet where I could learn these concepts without getting lost. You made it look so simple. Thank you very much!!! You are very talented in teaching!
@zombnie
@zombnie 4 жыл бұрын
i have been searching for a good source of comparison between these two for days. Finally one video which explains the difference perfectly. Thank you so much Navin
@user-bq2lb7kn2e
@user-bq2lb7kn2e 5 жыл бұрын
Normally I don't leave comments on these types of video's, but I must say that this video is very helpfull. I have an exam due tomorrow and just wanted a quick refresh of one of the subjects. Thank you!
@hasmi_intentart
@hasmi_intentart 5 жыл бұрын
Clearly explained, this is wt exactly I was expecting for😍
@filip8467
@filip8467 3 жыл бұрын
Comparator is a functional interface, so you can pass a logic directly by lambda through argumen list like that: Collections.sort(laps,(lap1,lap2)=>if lap1>la2 return 1 else return -1)
@jatinderarora2261
@jatinderarora2261 5 жыл бұрын
Awesome. Thanks for sharing your excellent knowledge !
@rudrakshjhalani1681
@rudrakshjhalani1681 5 жыл бұрын
The way you teach, makes one understand each topic so easily. Thank you Sir.
@dnyaneshtathode5511
@dnyaneshtathode5511 3 жыл бұрын
Naveen, you're just great!! Brilliant and hilariously easy-to-understand explanation. Not everyone has got the ability to teach things in a simple manner as you do..Einstein of Java I must say
@purnimadas3762
@purnimadas3762 5 жыл бұрын
Thank you very much, you have explained important concept so simply, and have made it very easy for the listeners to understand it. Thanks once again!
@AhmedVlogs1
@AhmedVlogs1 6 жыл бұрын
You made the concept so easy to understand.thank u sir
@gongjiaji2489
@gongjiaji2489 5 жыл бұрын
Thank you, clear and beautiful explanation.
@AshishBurnwal
@AshishBurnwal 6 жыл бұрын
You are awesome... You teach in such a manner that anyone can pick. Thank you so much
@habdochkeineahnung
@habdochkeineahnung 3 жыл бұрын
are you crazy? this was way too fast and he didnt explain what he did via autogenerate. thats not good teaching imho.
@mridulpaudel629
@mridulpaudel629 3 жыл бұрын
@@habdochkeineahnung his older videos explain all that. The title says interview questions where he assumes you already know the basics and are preparing for the interview.
@alperozdamar517
@alperozdamar517 4 жыл бұрын
The Simplest and the best explanation about "Comparable vs Comparator"
@IsaacAsante17
@IsaacAsante17 5 жыл бұрын
Your tutorial is perfect. Thanks.
@andreme7326
@andreme7326 3 жыл бұрын
I enjoy your tutorials! Thank you, Navin!
@hughsoward3484
@hughsoward3484 3 жыл бұрын
More CS professors should watch your videos to learn how to explain these concepts better. Thank you so much!
@purnimadas3762
@purnimadas3762 6 жыл бұрын
Thank you, your video on comparator and comparable made the concept so easy to understand. Simple and straightforward, thanks once again.
@mohammadmoslemuddin7274
@mohammadmoslemuddin7274 4 жыл бұрын
Mind-blowing explanation. Thank you
@dipak002
@dipak002 5 жыл бұрын
So well explained! Really appreciate... 👍
@sajidmohammed8553
@sajidmohammed8553 4 жыл бұрын
Simple..crisp...to the point! and concepts made easy!
@obsydian806
@obsydian806 4 жыл бұрын
This was such a helpful video. Thank you so much for making it.
@yatin1370
@yatin1370 Жыл бұрын
Hi Naveen, I thoroughly enjoyed the way you have put all the facts before us to understand this with crystal clarity! Thanks!
@deepakshakya9597
@deepakshakya9597 2 жыл бұрын
Your teaching skills are amazing!!! Thank you so much for making such valuable videos
@Pravin-hj2wj
@Pravin-hj2wj 3 жыл бұрын
Your explanation is really superb. I was able to quickly grasp why these interfaces are used & where used from this video. Thanks so so so much, Navin.
@bhanuprasad4952
@bhanuprasad4952 5 жыл бұрын
Clearly explained. Thanks a lot
@Sushil2874
@Sushil2874 4 жыл бұрын
Very well explained ..!! Thank you so much..!!
@ThatGuyAnonymous
@ThatGuyAnonymous 5 жыл бұрын
Wow, plain and clear, thanks Sir 👍
@kumarneeraj1996
@kumarneeraj1996 4 жыл бұрын
Great way of explaining, understood in one go
@Iam_Raam
@Iam_Raam 5 жыл бұрын
Nice explanation.... Thank you ....
@maneaniket4200
@maneaniket4200 5 жыл бұрын
Nobody does the job of using code to explain concepts... Great Naveen.. Thanks For The Video..
@jaaeamor7901
@jaaeamor7901 Жыл бұрын
Thanks for the video!
@kbhardwaj1989
@kbhardwaj1989 4 жыл бұрын
You explanation are always superb. Thanks you.
@ezhilarasikrishnan5408
@ezhilarasikrishnan5408 5 жыл бұрын
It's amazing... Great explanation..
@health.upgradedbyscience.7309
@health.upgradedbyscience.7309 Жыл бұрын
Brilliant explanation, so important to know both approaches - i was not aware of the second one before - thanks a million!! 😆
@AnirudhSharma9211
@AnirudhSharma9211 3 жыл бұрын
9:55 I just wanted to add that sorting based on Price can also be done using Comparable, if we override compareTo method to compare prices. Also, a major difference is that we can have multiple comparators in a class, but only one comparable. I experimented and tried to create a second compareTo method in my class using anonymous class, but failed because 'this' keyword wouldn't have scope inside the anonymous class. That's when I realized that compareTo actually compares the present instance of a class to the passed object, which is why there can be only one in a class. compare method has no such restrictions, and it doesn't even have to be in the same class, because it uses two distinctly defined objects.
@praneethachebolu278
@praneethachebolu278 Жыл бұрын
here inside the anonymous class we wrote compare() right? does it have to be compare() or can the be different like comparing() or comparePrice() or something?
@mohammadhaque1873
@mohammadhaque1873 4 жыл бұрын
Excellent. Awesome and no one likely to have problem understanding. Thank You.
@Evilshrimp02
@Evilshrimp02 3 жыл бұрын
This guy is the man. Thanks a lot.
@bharatmakkar9706
@bharatmakkar9706 Жыл бұрын
crystal clear explanation! thanks!
@josephwong2832
@josephwong2832 4 жыл бұрын
Excellent video Telusko, I've now subbed to your channel!!
@vision2k890
@vision2k890 4 жыл бұрын
Best explanation I've found, thanks
@maayoufamoez2217
@maayoufamoez2217 5 жыл бұрын
Excellent, Well done!
@DavidaThatch
@DavidaThatch Жыл бұрын
SO GOOD Thank you!!
@sreekanthreddy5942
@sreekanthreddy5942 6 жыл бұрын
Nice information.Thanks a lot ....
@saikumarnarani8173
@saikumarnarani8173 2 жыл бұрын
Simply Amazing..!!! Thank you so much
@clashwithjerin6127
@clashwithjerin6127 3 жыл бұрын
Perfect. i was roaming and watching different videos about this, Finally found the perfect one !!
@vladanulardzic5859
@vladanulardzic5859 4 жыл бұрын
Great explanation ! Keep on !
@nasamind
@nasamind 5 жыл бұрын
Nice.. your explanation is very simple.. I went through other explanations but yours is easy to understand..
@siteshp
@siteshp 5 жыл бұрын
Nice Explanation...
@akiratoriyama1320
@akiratoriyama1320 4 жыл бұрын
Great explanation!! Thank you sir!!
@jishuschannel
@jishuschannel 4 жыл бұрын
Very clean and clear way of explaining...no probable doubts you are leaving for your aliens...!!👍👍
@fRosT_verse
@fRosT_verse 6 жыл бұрын
damn good explanation... Much needed thanks sir :)
@ctapiero
@ctapiero 3 жыл бұрын
You saved my midterm! Thank you sir!
@ajaysimon3064
@ajaysimon3064 2 жыл бұрын
What a great video. Understood the concept clearly
@rahulkhandelwal46578
@rahulkhandelwal46578 3 жыл бұрын
Perfect explanation.Thanks
@ngneer5804
@ngneer5804 4 жыл бұрын
Very well explained, thank you.
@SuranjanaVlogsUSA
@SuranjanaVlogsUSA 5 жыл бұрын
Such picturesque explanation 👌
@shubhanksrivastava3590
@shubhanksrivastava3590 6 жыл бұрын
explained it, in quite and easy manner... Thanks a lot.
@maxboyar3484
@maxboyar3484 3 жыл бұрын
Nice well done!! good examples!
@kristiyangerasimov6708
@kristiyangerasimov6708 2 жыл бұрын
awesome video, thank you Telusko!
@hissabis2068
@hissabis2068 3 жыл бұрын
Great job, thanks.
@suryasikharej8116
@suryasikharej8116 5 жыл бұрын
I have never seen a teacher like you sir....you are damn awesome
@randyafriansyah9340
@randyafriansyah9340 4 жыл бұрын
thank you, I love your explanation
@rameshp4604
@rameshp4604 5 жыл бұрын
Thank you, I got clear picture about the comparable and comparator
@sankeths3508
@sankeths3508 Жыл бұрын
thank you sir, this video was crystal clear for me
@doniagasmi2192
@doniagasmi2192 2 жыл бұрын
great explanation! thank you
@shivaramkrishnadurgi4253
@shivaramkrishnadurgi4253 2 жыл бұрын
Mr. Perfect @Navin Reddy... Loved your teaching style...Awesome!!!
@anonimus4331
@anonimus4331 4 жыл бұрын
Thank you. Very informative video
@umeshchavan8215
@umeshchavan8215 6 жыл бұрын
great explanation..
@TheChuster
@TheChuster 5 жыл бұрын
Clean, efficient explanation. thanks
@mahajanram4311
@mahajanram4311 4 жыл бұрын
You are awesome!!! Thank you so much!!!
@MrPrakash57
@MrPrakash57 6 жыл бұрын
Thanks a lot navin. This is really helpful....
@kchemutai3483
@kchemutai3483 Жыл бұрын
Thank you so much, its very clear and precise
@chilinouillesdepommesdeter819
@chilinouillesdepommesdeter819 5 жыл бұрын
Consice and informative,great video
@Ahsu0108
@Ahsu0108 3 жыл бұрын
Thanks so much for the great explanation.
@greenxdshadow6635
@greenxdshadow6635 Жыл бұрын
bless you man, you make it so easy
@sachinchinnannavar9514
@sachinchinnannavar9514 5 жыл бұрын
Naveen sir i was having lot of confusion with this concepts thanks for exlpaining it clearly with example
@jomagaray5563
@jomagaray5563 4 жыл бұрын
thanks for the video !! greetings from Argentina !!
@96Ballons
@96Ballons Жыл бұрын
Great explanation and examples!
@satheshbm92
@satheshbm92 6 жыл бұрын
Great explanation :) Became a fan of you.
@subhakantaroul
@subhakantaroul 3 жыл бұрын
you are awesome! completely understood the concepts. before thins wherever I was reading about comparable and comparator, I was getting more confused.
@alexjohnlovesu
@alexjohnlovesu 6 жыл бұрын
Thanks, well explained
@shubhamnigam14
@shubhamnigam14 Жыл бұрын
Easy simple and crisp ❤thanks
@ravirai4828
@ravirai4828 5 жыл бұрын
Awsome..... clear and concise
@balakrishnamaddula3695
@balakrishnamaddula3695 3 жыл бұрын
Thanks for good explanation sir !
@hectorfred99
@hectorfred99 4 жыл бұрын
The best explanation.. Thanks a lot
@ferfykins
@ferfykins 2 жыл бұрын
Excellent video, very well explained, ty so much!
@rajenderprasad1193
@rajenderprasad1193 10 ай бұрын
You made it easy Sir. Thank you
@ArquimedesOfficial
@ArquimedesOfficial 3 жыл бұрын
Amazing tutorial man, thanks.
@laxmichandra4904
@laxmichandra4904 5 жыл бұрын
Sir your great .. you have given good teaching methodology.....thank you so much
@vadirajjahagirdar9342
@vadirajjahagirdar9342 6 жыл бұрын
You are awesome... You teach in such a manner that anyone can pick
@kuldeepsahoo5080
@kuldeepsahoo5080 5 жыл бұрын
thanks for explaining in such a nice way
@technophile7024
@technophile7024 2 жыл бұрын
Outstanding!
@dataguy7013
@dataguy7013 3 жыл бұрын
Very nice video on just the topics you are wondering about. Teluko, tussi great ho ji!
@kunalkheeva
@kunalkheeva Жыл бұрын
Thank you sir!
@rajasekaran1724
@rajasekaran1724 3 жыл бұрын
Awesome Explanation
@RishiKumar-xw5nd
@RishiKumar-xw5nd 5 жыл бұрын
very nice explanations...
@nagarajanerode
@nagarajanerode 3 жыл бұрын
Great explanation in a simplest way possible.
14.9 Set Interface in Java Collection Framework
6:12
Telusko
Рет қаралды 162 М.
#95 Comparator vs Comparable in Java
15:43
Telusko
Рет қаралды 145 М.
🍕Пиццерия FNAF в реальной жизни #shorts
00:41
⬅️🤔➡️
00:31
Celine Dept
Рет қаралды 42 МЛН
Functional Interface | Lambda Expression in Java
13:56
Telusko
Рет қаралды 136 М.
Generics in Java
14:26
Telusko
Рет қаралды 499 М.
MUST KNOW junior role JAVA interview questions
42:15
Keep On Coding
Рет қаралды 98 М.
Top 25 Microservice Interview Questions Answered - Java Brains
39:54
.equals() vs. == in Java - The Real Difference
8:48
Coding with John
Рет қаралды 179 М.
Java Spring Boot 14 Years Interview Experience [God Level Skills]
54:49
cute mini iphone
0:34
승비니 Seungbini
Рет қаралды 1,5 МЛН
Main filter..
0:15
CikoYt
Рет қаралды 9 МЛН
AI от Apple - ОБЪЯСНЯЕМ
24:19
Droider
Рет қаралды 131 М.
📦Он вам не медведь! Обзор FlyingBear S1
18:26