About 6,590,000 results
Open links in new tab
  1. 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 …

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

  3. java - How do I use a PriorityQueue? - Stack Overflow

    Mar 25, 2009 · How do I get a PriorityQueue to sort on what I want it to sort on? Also, is there a difference between the offer and add methods?

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

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

  5. Sort a list of lists with a custom compare function

    Generally, you want to use the built-in sorted() function which takes a custom comparator as its parameter. We need to pay attention to the fact that in Python 3 the parameter name and …

  6. java - Sort a Map<Key, Value> by values - Stack Overflow

    The comparator used for the treemap is inconsistent with equals (see the sortMap javadox). This means retireving items from the tree map will not work. sorted_map.get ("A") will return null. …

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

  8. Java Comparator class to sort arrays - Stack Overflow

    Say, we have the following 2-dimensional array: int camels[][] = new int[n][2]; How should Java Comparator class be declared to sort the arrays by their first elements in decreasing order …

  9. How do I use Comparator to define a custom sort order?

    Mar 9, 2011 · How do I use Comparator to define a custom sort order? Asked 14 years, 7 months ago Modified 5 years, 6 months ago Viewed 333k times

  10. Java get String CompareTo as a comparator object

    Aug 4, 2012 · 56 I would like to sort and binary search a static array of strings via the String.CompareTo comparator. The problem is that both sorting, and binary searching requires …