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

Veröffentlicht am: 29 November 2019
auf dem Kanal: Selenium Express
28,937
864

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.

   • How to sort in java? [ Comparable and Comp...  

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.
Comparator interface is there inside java.util package.
we can use the Collection.sort(list, newComparartorObject) to sort our list.
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.

   / @seleniumexpress  

Stay tuned and like my Facebook page for more.

  / seleniumexpress  

You can write your unsolved query to seleniumexpress@gmail.com.

Music :
-----------
credits : -
(intro)
Adventures by A Himitsu   / a-himitsu  
Creative Commons — Attribution 3.0 Unported— CC BY 3.0
http://creativecommons.org/licenses/b...
Music released by Argofox    • A Himitsu - Adventures [Royalty Free Music]  
Music provided by Audio Library    • Adventures – A Himitsu (No Copyright Music)  


intro template :
   / alexbau01  


Auf dieser Seite können Sie das Online-Video Sorting using Comparator | Comparable Vs Comparator | Java interview question | Java collections mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Selenium Express 29 November 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 28,937 Mal angesehen und es wurde von 864 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!