Top "Comparable" questions

In Java, this interface is implemented by a class to indicate that it can be compared to another object and therefore ordered.

What type of Exception should I throw if the wrong type of object is passed?

What type of Exception should I throw if the wrong type of object is passed into my compareTo method? ClassCastException?

java exception comparable
How to implement an interface with an enum, where the interface extends Comparable?

Consider this code: public interface Foo extends Comparable<Foo> {} public enum FooImpl implements Foo {} Due to the restrictions …

java generics interface enums comparable
What determines ascending or descending order in Comparator / Comparable collection class?

I understand we can sort or order the objects, stored in Collection as per our requirement(s). While I get …

java sorting collections interface comparable
Making your own class 'Comparable'

I followed a tutorial, but failed to make my Country class Comparable for my BST. Main: BinarySearchTree A = new BinarySearchTree(); …

java comparable
Compare two objects with "<" or ">" operators in Java

How to make two objects in Java comparable using "<" or ">" e.g. MyObject<String> obj1= new …

java object operator-overloading comparable
Implements Comparable to get alphabetical sort with Strings

I would like an object to be comparable (to use it in a TreeSet in that case). My object got …

java interface comparable implements alphabetical-sort
How does compareTo work?

I know that compareTo returns a negative or positive result on how well one string correlates to the other, but …

java equals comparable compareto
Java: removing "Comparable is a raw type" warning

Suppose I have a method called foo taking 2 Object as parameter. Both objects are of the same type and both …

java warnings comparable raw-types
Java priority queues and comparable interface

I've just been learning about priority queues and thought I'd try how it behaves with comparable interface. Code Snippet: import …

java priority-queue comparable
Java Generics: compareTo and "capture#1-of ?"

The following gives me an error message: public static List<Comparable<?>> merge(Set<List<…

java generics comparable