About 53 results
Open links in new tab
  1. 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 …

  2. java - When to use Comparable and Comparator - Stack Overflow

    Feb 15, 2010 · You create separate classes that implement the Comparator interface (or use lambdas in Java 8+) and define the compare () method. This is more flexible since you can …

  3. java - Difference between Comparable and Comparator? - Stack …

    Mar 30, 2018 · Comparable and Comparator are generic interfaces that allow to compare instances of the type defined in the generic (subclasses included). The main difference …

  4. When should I use Comparator vs Comparable? - Stack Overflow

    May 7, 2022 · It looks like the comparator defines the „natural order“ for Person objects. In this case, you should implement the Comparable interface and compareTo () instead. But …

  5. java - Diferença entre Comparator e Comparable - Stack Overflow …

    Nov 9, 2018 · Em Java, qual é a diferença entre essas duas interfaces, Comparator e Comparable? Quando usar uma ou outra?

  6. When should a class be Comparable and/or Comparator?

    Sep 17, 2009 · 245 The text below comes from Comparator vs Comparable Comparable A comparable object is capable of comparing itself with another object. The class itself must …

  7. 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 …

  8. Java 8 stream max () function argument type Comparator vs …

    Apr 15, 2019 · Java 8 stream max () function argument type Comparator vs Comparable Asked 6 years, 10 months ago Modified 6 years, 10 months ago Viewed 10k times

  9. How to use Comparator in Java to sort - Stack Overflow

    Again, to use Collections.sort, you need one of these to be true: The type must be Comparable (use the 1-arg sort) A Comparator for the type must be provided (use the 2-args sort) When to …

  10. java - Comparable and Comparator - Stack Overflow

    Feb 25, 2012 · In other words, a class that implements Comparable is capable of comparing itself to other objects of the same kind. From the Java documentation on Comparator: A comparison …