Java Reference
In-Depth Information
public static <T> T
max(Collection<? extends T> coll, Comparator<?
super T> comp)
Returns the largest valued element of the collection according
to the comparator
comp
.
The declarations of the type variables for two of these methods seem
rather complex. Basically, they just declare that
T
is a
Comparable
type.
The inclusion of "
extendsObject
" might seem redundant, but it changes
the erasure of
T
to be
Object
rather than
Comparable
.
You can obtain a
Comparator
that will reverse the natural ordering of the
objects it compares, or that of a given comparator:
public static <T> Comparator<T>
reverseOrder()
Returns a
Comparator
that reverses the natural ordering of the
objects it compares.
public static <T> Comparator<T>
reverseOrder(Comparator<T> comp)
Returns a
Comparator
the reverses the order of the given com-
parator.
Then there are some general convenience methods for collections:
public static <T> boolean
addAll(Collection<? super T> coll, T...
elems)
Adds all of the specified elements to the given collection, re-
turning
true
if the collection was changed. Naturally, if the col-
lection does not support the
add
method then
UnsupportedOper-
ationException
is thrown.
public static boolean
disjoint(Collection<?> coll1, Collection<?>
coll2)