Interview Question | Comparable vs Comparator Detailed Explanation with Example In Java | JavaTechie

Поділитися
Вставка
  • Опубліковано 19 жов 2024

КОМЕНТАРІ • 36

  • @RaviShankar-xy6zh
    @RaviShankar-xy6zh 2 роки тому +5

    Buddy you always bring the insights of strong concepts through your eloquent videos. Need of the hour

  • @sivajames07
    @sivajames07 2 роки тому +2

    This is the most interview question I have been asked for many times

  • @vasanthraj3883
    @vasanthraj3883 5 місяців тому +1

    Very helpful for me, thanks sir.

  • @sujithasugumar543
    @sujithasugumar543 Рік тому +1

    Awesome explanation thanks a lot

  • @arhianalbis918
    @arhianalbis918 Рік тому +1

    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?

    • @Javatechie
      @Javatechie  Рік тому

      I will definitely try that

    • @arhianalbis918
      @arhianalbis918 Рік тому +1

      @@Javatechie Great. I would love to know if it works.

  • @josephthecreator
    @josephthecreator 2 роки тому +1

    Extremely helpful, thank you for this tutorial!

  • @arhianalbis918
    @arhianalbis918 Рік тому +1

    The T chart at 0:55 is gold!!

  • @shyaammuthusamy7370
    @shyaammuthusamy7370 Рік тому +1

    Awesome explanation.

  • @imBalji
    @imBalji 2 роки тому +1

    Excellent explanation. Thankyou sir

  • @adityavyas6603
    @adityavyas6603 2 роки тому +1

    Java Basant..
    Very good video
    Please create video on Junit testing
    Mockito wiremock etc

    • @Javatechie
      @Javatechie  2 роки тому

      Hi Aditya , mockito video is already there please check in my channel

  • @anugantigowtham
    @anugantigowtham 2 роки тому

    Explanation is straight to the point but , it would have been better if you had explained the contract between hashcode and equals also.

  • @vengateshm2122
    @vengateshm2122 2 роки тому +1

    Indeed very useful. Thank you.

  • @RAJU9622
    @RAJU9622 2 роки тому +1

    Thanks Basant is it any different way we can achieve using Java8 streams?

    • @Javatechie
      @Javatechie  2 роки тому +1

      Yes buddy . Already i explained how to use functional interface with lambda please checkout my java 8 playlist

  • @ShinAkuma
    @ShinAkuma 2 роки тому +3

    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.

    • @Javatechie
      @Javatechie  2 роки тому +5

      Thanks buddy this we can do using grouping method of stream

  • @sathiskumarp
    @sathiskumarp 2 роки тому +1

    Good one

  • @natureParadise777
    @natureParadise777 2 роки тому +1

    Good one, please keep uploading video like this

  • @ashimroy3891
    @ashimroy3891 11 місяців тому +2

    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 ?

    • @Javatechie
      @Javatechie  11 місяців тому

      Of course it's wrong that's the point of equals and hashcode contract you need to customize it as per your usecase

  • @jyotisstyle
    @jyotisstyle 2 роки тому

    Sir, Can you please make one video on STATIC keyword? In interview they always ask about static keyword in JAVA.
    Thank you in advance.

  • @kumaresanperumal2581
    @kumaresanperumal2581 2 роки тому +1

    Thanks

  • @crazycom7819
    @crazycom7819 2 роки тому +1

    Good topic

  • @foodgallery5819
    @foodgallery5819 Рік тому +1

    Thank you :)

  • @pramitranjan4338
    @pramitranjan4338 2 роки тому +1

    Bhai please make logical coding video using Java 8

  • @tanujkumaragrawal4756
    @tanujkumaragrawal4756 2 роки тому +1

  • @ktmurali3274
    @ktmurali3274 2 роки тому +1

    Please upload ReactJs

  • @ktmurali3274
    @ktmurali3274 2 роки тому

    Please upload ReactJs it is more helpful us

  • @fuadgafarov
    @fuadgafarov 2 роки тому +1

    Thanks