Interview Question | Comparable vs Comparator in Java

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

Telusko

Telusko

6 жыл бұрын

Check out our courses:
Spring and Microservices Weekend Live Batch : bit.ly/spring-live-weekend
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : bit.ly/java-spring-cloud
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
@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.
@raragam
@raragam 4 жыл бұрын
This guy is simply amazing. Hats off to his teaching abilities !!
@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)
@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
@steviet5246
@steviet5246 5 жыл бұрын
I'm here to learn for my exams, nobody explained it so simple like you thanks!
@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😍
@rudrakshjhalani1681
@rudrakshjhalani1681 5 жыл бұрын
The way you teach, makes one understand each topic so easily. Thank you Sir.
@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?
@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
@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.
@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!
@alperozdamar517
@alperozdamar517 4 жыл бұрын
The Simplest and the best explanation about "Comparable vs Comparator"
@jatinderarora2261
@jatinderarora2261 5 жыл бұрын
Awesome. Thanks for sharing your excellent knowledge !
@hughsoward3484
@hughsoward3484 3 жыл бұрын
More CS professors should watch your videos to learn how to explain these concepts better. Thank you so much!
@AhmedVlogs1
@AhmedVlogs1 6 жыл бұрын
You made the concept so easy to understand.thank u sir
@purnimadas3762
@purnimadas3762 6 жыл бұрын
Thank you, your video on comparator and comparable made the concept so easy to understand. Simple and straightforward, thanks once again.
@gongjiaji2489
@gongjiaji2489 5 жыл бұрын
Thank you, clear and beautiful explanation.
@maneaniket4200
@maneaniket4200 5 жыл бұрын
Nobody does the job of using code to explain concepts... Great Naveen.. Thanks For The Video..
@IsaacAsante17
@IsaacAsante17 5 жыл бұрын
Your tutorial is perfect. Thanks.
@andreme7326
@andreme7326 3 жыл бұрын
I enjoy your tutorials! Thank you, Navin!
@mohammadmoslemuddin7274
@mohammadmoslemuddin7274 4 жыл бұрын
Mind-blowing explanation. Thank you
@deepakshakya9597
@deepakshakya9597 2 жыл бұрын
Your teaching skills are amazing!!! Thank you so much for making such valuable videos
@ThatGuyAnonymous
@ThatGuyAnonymous 5 жыл бұрын
Wow, plain and clear, thanks Sir 👍
@kumarneeraj1996
@kumarneeraj1996 5 жыл бұрын
Great way of explaining, understood in one go
@obsydian806
@obsydian806 4 жыл бұрын
This was such a helpful video. Thank you so much for making it.
@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.
@yatin1370
@yatin1370 Жыл бұрын
Hi Naveen, I thoroughly enjoyed the way you have put all the facts before us to understand this with crystal clarity! Thanks!
@sajidmohammed8553
@sajidmohammed8553 4 жыл бұрын
Simple..crisp...to the point! and concepts made easy!
@bhanuprasad4952
@bhanuprasad4952 5 жыл бұрын
Clearly explained. Thanks a lot
@clashwithjerin6127
@clashwithjerin6127 3 жыл бұрын
Perfect. i was roaming and watching different videos about this, Finally found the perfect one !!
@mohammadhaque1873
@mohammadhaque1873 4 жыл бұрын
Excellent. Awesome and no one likely to have problem understanding. Thank You.
@Sushil2874
@Sushil2874 4 жыл бұрын
Very well explained ..!! Thank you so much..!!
@suryasikharej8116
@suryasikharej8116 5 жыл бұрын
I have never seen a teacher like you sir....you are damn awesome
@dipak002
@dipak002 5 жыл бұрын
So well explained! Really appreciate... 👍
@vision2k890
@vision2k890 4 жыл бұрын
Best explanation I've found, thanks
@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!! 😆
@Evilshrimp02
@Evilshrimp02 3 жыл бұрын
This guy is the man. Thanks a lot.
@rameshp4604
@rameshp4604 5 жыл бұрын
Thank you, I got clear picture about the comparable and comparator
@kbhardwaj1989
@kbhardwaj1989 4 жыл бұрын
You explanation are always superb. Thanks you.
@ezhilarasikrishnan5408
@ezhilarasikrishnan5408 5 жыл бұрын
It's amazing... Great explanation..
@randyafriansyah9340
@randyafriansyah9340 4 жыл бұрын
thank you, I love your explanation
@Iam_Raam
@Iam_Raam 5 жыл бұрын
Nice explanation.... Thank you ....
@sachinchinnannavar9514
@sachinchinnannavar9514 5 жыл бұрын
Naveen sir i was having lot of confusion with this concepts thanks for exlpaining it clearly with example
@fRosT_verse
@fRosT_verse 6 жыл бұрын
damn good explanation... Much needed thanks sir :)
@siteshp
@siteshp 5 жыл бұрын
Nice Explanation...
@maayoufamoez2217
@maayoufamoez2217 5 жыл бұрын
Excellent, Well done!
@krishnakrishna-yh9ly
@krishnakrishna-yh9ly 3 жыл бұрын
Great
@kavya5808
@kavya5808 5 жыл бұрын
How can someone teach so well. You are awesome.
@akiratoriyama1320
@akiratoriyama1320 4 жыл бұрын
Great explanation!! Thank you sir!!
@SuranjanaVlogsUSA
@SuranjanaVlogsUSA 5 жыл бұрын
Such picturesque explanation 👌
@ctapiero
@ctapiero 3 жыл бұрын
You saved my midterm! Thank you sir!
@shivaramkrishnadurgi4253
@shivaramkrishnadurgi4253 2 жыл бұрын
Mr. Perfect @Navin Reddy... Loved your teaching style...Awesome!!!
@nasamind
@nasamind 5 жыл бұрын
Nice.. your explanation is very simple.. I went through other explanations but yours is easy to understand..
@shubhanksrivastava3590
@shubhanksrivastava3590 6 жыл бұрын
explained it, in quite and easy manner... Thanks a lot.
@jaaeamor7901
@jaaeamor7901 Жыл бұрын
Thanks for the video!
@josephwong2832
@josephwong2832 4 жыл бұрын
Excellent video Telusko, I've now subbed to your channel!!
@Jermiah-tj9qe
@Jermiah-tj9qe 5 жыл бұрын
I love watch your java tutorials Sir :) can you make a tutorial for CPU scheduling having a gantt chart? If you do Sir, i will influence more of my classmates to watch your Knowledgeable tutorials. Thank You so much!
@ngneer5804
@ngneer5804 4 жыл бұрын
Very well explained, thank you.
@jishuschannel
@jishuschannel 4 жыл бұрын
Very clean and clear way of explaining...no probable doubts you are leaving for your aliens...!!👍👍
@sreekanthreddy5942
@sreekanthreddy5942 6 жыл бұрын
Nice information.Thanks a lot ....
@dgabrielm
@dgabrielm 6 жыл бұрын
Hi Navin, thanks so much for making this video. It is really clear and logical and gives you the understanding of WHY we use each one. compareTo(myUniversityProfessor) who just writes the syntax on the board and shrugs his shoulders. Brilliant!
@pranavnyavanandi9710
@pranavnyavanandi9710 Жыл бұрын
Pretty cool man, that compareTo().
@jomagaray5563
@jomagaray5563 4 жыл бұрын
thanks for the video !! greetings from Argentina !!
@bharatmakkar9706
@bharatmakkar9706 Жыл бұрын
crystal clear explanation! thanks!
@chilinouillesdepommesdeter819
@chilinouillesdepommesdeter819 5 жыл бұрын
Consice and informative,great video
@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.
@saikumarnarani8173
@saikumarnarani8173 2 жыл бұрын
Simply Amazing..!!! Thank you so much
@vladanulardzic5859
@vladanulardzic5859 4 жыл бұрын
Great explanation ! Keep on !
@sankeths3508
@sankeths3508 Жыл бұрын
thank you sir, this video was crystal clear for me
@ajaysimon3064
@ajaysimon3064 2 жыл бұрын
What a great video. Understood the concept clearly
@laxmichandra4904
@laxmichandra4904 5 жыл бұрын
Sir your great .. you have given good teaching methodology.....thank you so much
@sunnysaini4320
@sunnysaini4320 6 жыл бұрын
sir great .....i m java developer.....your teach way is too good(tussi kmaal krde hunde aa)
@rahulkhandelwal46578
@rahulkhandelwal46578 3 жыл бұрын
Perfect explanation.Thanks
@kchemutai3483
@kchemutai3483 Жыл бұрын
Thank you so much, its very clear and precise
@DavidaThatch
@DavidaThatch Жыл бұрын
SO GOOD Thank you!!
@vadirajjahagirdar9342
@vadirajjahagirdar9342 6 жыл бұрын
You are awesome... You teach in such a manner that anyone can pick
@sagardarade
@sagardarade 3 жыл бұрын
Crystal clear in short time
@TheChuster
@TheChuster 5 жыл бұрын
Clean, efficient explanation. thanks
@kristiyangerasimov6708
@kristiyangerasimov6708 2 жыл бұрын
awesome video, thank you Telusko!
@bimalkumar712
@bimalkumar712 3 жыл бұрын
Cool...nice contents
@technophile7024
@technophile7024 2 жыл бұрын
Outstanding!
@anonimus4331
@anonimus4331 4 жыл бұрын
Thank you. Very informative video
@umeshchavan8215
@umeshchavan8215 6 жыл бұрын
great explanation..
@pankajmalvi6761
@pankajmalvi6761 5 жыл бұрын
finally "THIS" ka doubt solve hua ,,, i knew this but just cant clicked :-D
@mahajanram4311
@mahajanram4311 4 жыл бұрын
You are awesome!!! Thank you so much!!!
@rajasekaran1724
@rajasekaran1724 3 жыл бұрын
Awesome Explanation
@ravirai4828
@ravirai4828 5 жыл бұрын
Awsome..... clear and concise
@abrehamish
@abrehamish 3 жыл бұрын
Well explained
@hissabis2068
@hissabis2068 3 жыл бұрын
Great job, thanks.
@alexjohnlovesu
@alexjohnlovesu 6 жыл бұрын
Thanks, well explained
@Ahsu0108
@Ahsu0108 3 жыл бұрын
Thanks so much for the great explanation.
@MrPrakash57
@MrPrakash57 6 жыл бұрын
Thanks a lot navin. This is really helpful....
@Efocusto
@Efocusto 2 жыл бұрын
nice work big like
@bostonlights2749
@bostonlights2749 3 жыл бұрын
Wow! Just wow!
@kuldeepsahoo5080
@kuldeepsahoo5080 5 жыл бұрын
thanks for explaining in such a nice way
@rajenderprasad1193
@rajenderprasad1193 10 ай бұрын
You made it easy Sir. Thank you
@96Ballons
@96Ballons Жыл бұрын
Great explanation and examples!
@shubhamnigam14
@shubhamnigam14 Жыл бұрын
Easy simple and crisp ❤thanks
@doniagasmi2192
@doniagasmi2192 2 жыл бұрын
great explanation! thank you
14.9 Set Interface in Java Collection Framework
6:12
Telusko
Рет қаралды 162 М.
#95 Comparator vs Comparable in Java
15:43
Telusko
Рет қаралды 147 М.
Backstage 🤫 tutorial #elsarca #tiktok
00:13
Elsa Arca
Рет қаралды 48 МЛН
СНЕЖКИ ЛЕТОМ?? #shorts
00:30
Паша Осадчий
Рет қаралды 8 МЛН
I’m just a kid 🥹🥰 LeoNata family #shorts
00:12
LeoNata Family
Рет қаралды 16 МЛН
Functional Interface | Lambda Expression in Java
13:56
Telusko
Рет қаралды 137 М.
Generics in Java
14:26
Telusko
Рет қаралды 500 М.
MUST KNOW junior role JAVA interview questions
42:15
Keep On Coding
Рет қаралды 99 М.
Top 25 Microservice Interview Questions Answered - Java Brains
39:54
.equals() vs. == in Java - The Real Difference
8:48
Coding with John
Рет қаралды 179 М.
Stream API in Java
26:04
Telusko
Рет қаралды 278 М.
14.11 HashMap and HashTable in Java
8:44
Telusko
Рет қаралды 668 М.
Will the battery emit smoke if it rotates rapidly?
0:11
Meaningful Cartoons 183
Рет қаралды 31 МЛН
Телефон в воде 🤯
0:28
FATA MORGANA
Рет қаралды 1,2 МЛН
Какой ПК нужен для Escape From Tarkov?
0:48
CompShop Shorts
Рет қаралды 270 М.