Interview Question | Comparable vs Comparator Detailed Explanation with Example In Java | JavaTechie
Vložit
- čas přidán 7. 01. 2022
- This tutorial You will learn What is Comparable & Comparator in Java
When to use Comparable
When to use Comparator
How to add multi compare logic using Comparator
#javatechie #InterviewQA #Java #Collection
GitHub:
github.com/Java-Techie-jt/
Blogs:
/ javatechie
Facebook:
/ 919464521471923
guys if you like this video please do subscribe now and press the bell icon to not miss any update from Java Techie
Disclaimer/Policy:
--------------------------------
Note : All uploaded content in this channel is mine and its not copied from any community ,
you are free to use source code from above mentioned GitHub account - Věda a technologie
Buddy you always bring the insights of strong concepts through your eloquent videos. Need of the hour
Thanks buddy
Very helpful for me, thanks sir.
Extremely helpful, thank you for this tutorial!
Excellent explanation. Thankyou sir
Indeed very useful. Thank you.
This is the most interview question I have been asked for many times
Good one
Awesome explanation.
Awesome explanation thanks a lot
Good topic
The T chart at 0:55 is gold!!
Thank you :)
Thanks
❤
Good one, please keep uploading video like this
Explanation is straight to the point but , it would have been better if you had explained the contract between hashcode and equals also.
Java Basant..
Very good video
Please create video on Junit testing
Mockito wiremock etc
Hi Aditya , mockito video is already there please check in my channel
Sir, Can you please make one video on STATIC keyword? In interview they always ask about static keyword in JAVA.
Thank you in advance.
If ever encountered that two objects have the same ID, what if I straight away deny that it is not possible. Will it be wrong ?
Of course it's wrong that's the point of equals and hashcode contract you need to customize it as per your usecase
Question: could you make a generic comparator if instead of passing you pass it and then you could sort any type of object by name or id or whichever parameter you specify, not only Student-type objects?
I will definitely try that
@@Javatechie Great. I would love to know if it works.
Thanks Basant is it any different way we can achieve using Java8 streams?
Yes buddy . Already i explained how to use functional interface with lambda please checkout my java 8 playlist
Not a good idea to create a separate class for every different comparator. Better to use lambda expression in Collections.sort();
I also faced this question today in an interview.
Suppose I have an Employee class like this,
Employee has a EmployeeID, EmployeeName and Department.
Now I have a Map like this. HashMap = new HashMap();
Sample data:
hm.put( new Employee(1, "Basant", "DepA") , 0);
hm.put( new Employee(2, "Rahul", "DepB") , 0);
hm.put( new Employee(3, "Sunny", "DepA") , 0);
Now using Stream, I need to get the result like this.
[ DepA => [Basant, Sunny] , DepB => [ Rahul ] ]
Basically we create a Department pojo with String name variable. And return the result in this format.
ArrayList< ArrayList >.
I wasn't able to do it at the moment in the interview, but later on I did it,
If you could cover this questions in a video as well, it would be very helpful to a lot of people.
Thanks buddy this we can do using grouping method of stream
Bhai please make logical coding video using Java 8
Yes I will do than
Please upload ReactJs
Will start soon
Please upload ReactJs it is more helpful us
Thanks