JDK-6356743 : java.util.Arrays does not have min(T[]), max(T[]) methods.
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • Submitted: 2005-11-30
  • Updated: 2016-09-02
  • Resolved: 2016-09-02
Related Reports
Relates :  
Relates :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
It is inconsistent for Java to support taking the extrema of an arbitrary collection through Collections.min(...) and Collections.max(...) but not of an arbitrary array.  Particularly, primitive arrays (which cannot be wrapped through Arrays.asList(T[])) require each application to supply its own minimum and maximum loop.

JUSTIFICATION :
 - Duplicate code throughout many applications is a waste of developer time.
 - Inconsistency between the treatment of arrays and collections is a very visible "wart" on the Java platform.

Comments
In Java 8 one can do Arrays.stream(array).min() or .max(), if array is int[], long[], or double[]. If the array is of another type, one can do IntStream.range(0, array.length).reduce((a, b) -> array[a] < array[b] ? a : b) to get an OptionalInt containing the index of the minimum element in the array. Closing as Not an Issue.
02-09-2016

EVALUATION The submitter is correct, but.... - the presence of primitive types leads naturally to multiple overloadings - arrays and generics don't work together perfectly which makes this suggestion less compelling than in Collections.
30-11-2005