Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Core Java - Interview Questions and Answers for 'Comparator' - 2 question(s) found - Order By Newest | ||||
| ||||
Ans. The purpose of comparator interface is to compare objects of the same class to identify the sorting order. Sorted Collection Classes ( TreeSet, TreeMap ) have been designed such to look for this method to identify the sorting order, that is why class need to implement Comparator interface to qualify its objects to be part of Sorted Collections. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   treemap   treeset   comparator Asked in 2 Companies Intermediate | ||||
Try 2 Question(s) Test | ||||
Related Questions | ||||
Difference beween HashSet and TreeSet ? | ||||
If I try to add Enum constants to a TreeSet, What sorting order will it use ? | ||||
Which are the sorted collections ? | ||||
If we add Enum constants to a sorted collection ( Treemap , TreeSet ), What will be the order in which they will be maintained ? | ||||
What is the difference between TreeSet and TreeMap ? | ||||
Which of the following is insertion heavy - HashSet or TreeSet ? | ||||
How to sort objects based on one of the field ? | ||||
Frequently asked in CTS ( Based on 2 feedback ) | ||||
| ||||
Ans. Comparable interface is used for single sequence sorting i.e.sorting the objects based on single data member where as comparator interface is used to sort the object based on multiple data members. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java.util   comparable   comparator   collections Asked in 23 Companies basic   frequent | ||||
Related Questions | ||||
What is comparator interface used for ? | ||||
Sort a List of Objects using comparable and comparator | ||||
What is a comparator ? | ||||