Searches the specified collection for the maximum element. @param collection the collection to search. @return the maximum element in the Collection. @throws ClassCastException when an element in the collection does not implement Comparable or elements can
(
Collection<? extends T> collection)
| 1659 | * other. |
| 1660 | */ |
| 1661 | public static <T extends Object & Comparable<? super T>> T max( |
| 1662 | Collection<? extends T> collection) { |
| 1663 | Iterator<? extends T> it = collection.iterator(); |
| 1664 | T max = it.next(); |
| 1665 | while (it.hasNext()) { |
| 1666 | T next = it.next(); |
| 1667 | if (max.compareTo(next) < 0) { |
| 1668 | max = next; |
| 1669 | } |
| 1670 | } |
| 1671 | return max; |
| 1672 | } |
| 1673 | |
| 1674 | /** |
| 1675 | * Searches the specified collection for the maximum element using the |