Java Utililty Methods Collection Max

List of utility methods to do Collection Max

Description

The list of methods to do Collection Max are organized into topic(s).

Method

Collectionmax(Collection col)
Return a Collection of all highest-valued T .
if (col == null || col.isEmpty())
    return null;
Collection<T> result = sizedArrayList(col.size());
Iterator<T> it = col.iterator();
T max = it.next();
result.add(max);
while (it.hasNext()) {
    T next = it.next();
...
Tmax(Collection elems)
max
T max = null;
for (T t : elems) {
    if (max == null || max.compareTo(t) < 0) {
        max = t;
return max;
Tmax(Collection values)
max
T max = null;
Iterator<T> it = values.iterator();
if (it.hasNext()) {
    max = it.next();
    while (it.hasNext()) {
        T n = it.next();
        if (n.compareTo(max) > 0) {
            max = n;
...
Tmax(Collection values)
Returns the maximum of the given values.
T max = null;
for (T value : values) {
    if (max == null) {
        max = value;
        continue;
    @SuppressWarnings("unchecked")
    Comparable<T> comparable = (Comparable<T>) value;
...
Integermax(final Collection values)
Returns the max value in the collection.
Integer max = null;
for (Integer value : values) {
    if (value == null) {
        continue;
    if (max == null || value > max) {
        max = value;
return max;
Tmax(final Collection collection)
max
if (collection == null || collection.size() <= 0) {
    return null;
T max = null;
for (final T elem : collection) {
    if (max == null || elem.compareTo(max) > 0) {
        max = elem;
return max;
intmaxLength(Collection strings)
Returns the max String length from a Collection .
if (strings == null)
    throw new NullPointerException("strings cannot be null");
Iterator<String> i = strings.iterator();
int max = 0;
while (i.hasNext()) {
    String str = i.next();
    if (str != null) {
        int l = str.length();
...
TmaxOr(Collection values, T defaultVal)
Like Collections#max(java.util.Collection) except with a default value returned in the case of an empty collection.
if (values.isEmpty()) {
    return defaultVal;
} else {
    return Collections.max(values);
TminOrMax(int sign, Collection values)
min Or Max
if (values.isEmpty()) {
    return null;
T result = values.iterator().next();
for (T value : values) {
    if (value == null) {
        continue;
    if ((result == null) || (result.compareTo(value) * sign < 0)) {
        result = value;
return result;
List>partitionFixed(int maxNumChunks, Collection coll)
Fills up chunks out of a collection (given a maximum amount of chunks) i.e.
List<List<T>> ret = new ArrayList<>();
if (maxNumChunks == 0 || coll == null) {
    return ret;
Map<Integer, Integer> parts = integerDivided(coll.size(), maxNumChunks);
List<Integer> sortedKeys = new ArrayList<Integer>(parts.keySet());
Collections.sort(sortedKeys, Collections.reverseOrder());
Iterator<T> it = coll.iterator();
...