Top "Comparator" questions

A Common interface to create an object that specifies the way of comparing other objects.

How to sort ArrayList using Comparator?

I have a Class Student that Implements a static method public static Comparator<Student> getCompByName() that returns a …

java sorting collections arraylist comparator
TreeSet constructor with Comparator<?> parameter

In Java’s documentation for its class TreeSet one of the constructors is shown to have the following header: TreeSet(…

java generics comparator treeset
What's the sort order of Java's Collections.sort(list, comparator)? small to big or big to small?

Apparently, it's not documented or I missed it. Here's the link to the documentation and below's the text as an …

java sorting collections comparator
How to use the Comparator interface

I'm new to java, and I'm not really getting how to use the comparator interface. I have an ArrayList of …

java interface sorting comparator
Create a SortedMap in Java with a custom Comparator

I want to create a TreeMap in Java with a custom sort order. The sorted keys which are string need …

java string sorting comparator treemap
Java: SortedMap, TreeMap, Comparable? How to use?

I have a list of objects I need to sort according to properties of one of their fields. I've heard …

java interface comparator treemap sortedmap
Making a generic comparator class

I'm trying to make a comparator that can take any type of an element to compare. I'm unsure about how …

java generics types comparator
Java 8 Lambda: Comparator

I want to sort a list with Lambda: List<Message> messagesByDeviceType = new ArrayList<Message>(); messagesByDeviceType.sort((…

java lambda java-8 comparator
Java: to use contains in a ArrayList full of custom object should I override equals or implement Comparable/Comparator?

I have an ArrayList full of these: class TransitionState { Position positionA; Position positionB; int counter; public boolean equals (Object o){ …

java collections equals comparator comparable
STL Priority Queue on custom class

I'm having a lot of trouble getting my priority queue to recognize which parameter it should sort by. I've overloaded …

c++ stl priority-queue comparator