javacollectionsmaxstandard-library

Collections.max function for Iterable<Integer> in Java


The Java Collections.max method takes only a collection of a sortable (Comparable) object. However since the collection is not necessarily sorted, I don't see any reason not to implement the same max function for Iterable types.

Is there a max method for Iterable<T extends Comparable<? super T>> in Java's standard library?


Solution

  • Collections.max was introduced in 1.2. Iterable was introduced in 1.5.

    It's rare to have an Iterable that is not a Collection. If you do then it's straightforward to implement (be careful to read the spec). If you think it is really important you can submit an RFE in the Java Bug Database (or vote if there is already one there).