About 15,900 results
Open links in new tab
  1. java - When to use Comparable and Comparator - Stack Overflow

    Feb 15, 2010 · Use Comparable if you want to define a default (natural) ordering behaviour of the object in question, a common practice is to use a technical or natural (database?) identifier of …

  2. Java : Comparable vs Comparator - Stack Overflow

    Comparable should be implemented inside the object. So there is a dependency created with the compareTo method for a object which will be implied to a particular kind of implementation of …

  3. java - Comparator with double type - Stack Overflow

    1 Use Double.compare(/**double value 1*/, /**double value 2*/); with a new Comparator for your model class double value.

  4. java - How to compare objects by multiple fields - Stack Overflow

    You can implement a Comparator which compares two Person objects, and you can examine as many of the fields as you like. You can put in a variable in your comparator that tells it which …

  5. java - What is the difference between compare () and compareTo ...

    Jan 7, 2009 · From JavaNotes: a.compareTo(b): Comparable interface : Compares values and returns an int which tells if the values compare less than, equal, or greater than. If your class …

  6. java - В чем разница между Comparable и Comparator? - Stack …

    Mar 14, 2017 · Comparator и Comparable - это оба интерфейсы Коллекция (ну хорошо, объект) является Comparable, когда объект может быть как то сравнен с другим …

  7. Java 8 Lambda: Comparator - Stack Overflow

    Comparator We use comparator interface to sort homogeneous and heterogeneous elements for default, customized sorting order. int compare(T o1, T o2); it takes two arguments for ordering. …

  8. What do the return values of Comparable.compareTo mean in Java?

    Sep 22, 2010 · Java Generics and Collections by Maurice Naftalin, Philip Wadler, chapter 3.1: Comparable Warning: you should never rely on the return values of compareTo being -1, 0 and 1.

  9. java comparator, how to sort by integer? - Stack Overflow

    For example, a Comparator<Dog> to sort Dog instances descending by age could be created with the following: Comparable.comparingToInt(Dog::getDogAge).reversed(); The function take a …

  10. comparable - How to override compareTo (Java) - Stack Overflow

    I'm a beginner in programming and I have two classes. First class is: public class User implements Comparable&lt;User&gt; with field int age, constructor and overrided method of …