Java Coding Interview Questions and Answers | Sorting using comparator | Code Decode | [Most Common]

Publié le: 25 mai 2022
sur la chaîne: Code Decode
110,573
1.7k

In this video of code decode we have covered sorting using comparator which is common in Java coding interview question and answers for experienced

Udemy Course of Code Decode on Microservice k8s AWS CICD link:
https://openinapp.co/udemycourse

Course Description Video :
https://yt.openinapp.co/dmjvd

Write a Comparator in Java to compare two employees based upon name, age and Address?

This Programming Interview Question is very commonly asked for Experienced Java software developers.

In order to sort Employee object on different criteria, we need to create multiple comparators e.g. NameComparator, AgeComparator, and AddressComparator, this is known as custom sorting in Java.

This is different from the natural ordering of objects, provided by the compareTo() method of java.lang.Comparable interface.

Compare method returns
Negative if 1st parameter is 2nd parameter
Positive if 1st parameter is 2nd parameter
0 if 1st parameter is = 2nd parameter

This is also a very popular hackerrank problem which Interviewer asked you solved as a Experienced Java Developer

Ordering objects of user-defined classes is done using a comparator interface. A comparator object can compare two objects that belong to the same class. Compare obj1 and obj2 using the following function.

A user-defined class's objects are ordered using the Java Comparator interface.

The compare(Object obj1,Object obj2) and equals methods are both included in the java.util package (Object element).

It supports different sorting sequences, which means you can order the items by any data member, such as rollno, name, age, or anything else.

Most Asked Core Java Interview Questions and Answers :    • Core Java frequently asked Interview Quest...  

Advance Java Interview Questions and Answers :    • Advance Java Interview Questions  

Java 8 Interview Questions and Answers :    • Java 8 Interview Questions(New Features)  

Hibernate Interview Questions and Answers :    • Hibernate Interview Questions Java  

Spring Boot Interview Questions and Answers :    • Advance Java Interview Questions  

Angular Playlist :    • Angular Course Introduction || Angular 8  

SQL Playlist :    • SQL Interview Questions and Answers  

GIT :    • GIT  

Subscriber and Follow Code Decode
Subscriber Code Decode : https://www.youtube.com/c/CodeDecode?...
LinkedIn :   / codedecodeyoutube  
Instagram :   / codedecode25  

#codedecode #javacodinginterviewquestion #javainterviewquestion


Sur cette page du site, vous pouvez voir la vidéo en ligne Java Coding Interview Questions and Answers | Sorting using comparator | Code Decode | [Most Common] durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Code Decode 25 mai 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 110,573 fois et il a aimé 1.7 mille téléspectateurs. Bon visionnage!