Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8194664

add Comparator.comparingArray and thenComparingArray

XMLWordPrintable

      A DESCRIPTION OF THE REQUEST :
      There isn't a good way to create an anonymous Comparator instance for arrays based on a property of the array object.
      For example if you have an array of Potatoes and you want to compare them using their weigth as comparable object, this is not easily possible.

      JUSTIFICATION :
      It's currently very ugly to create a anonymous Comparator class to compare arrays based on a key.
      For "normal" Objects this is possible using Comparator#comparing(Function, Comparator), not so much for arrays or any other type of collection
      There really should be a convinience method like all the other default convinience thenComaring methods implemented by the comparator interface


      CUSTOMER SUBMITTED WORKAROUND :
      With Java 9 the following should work:
      (array1, array2) -> Arrays.compare(array1, array2, Comparator.comparing(Function))

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: