Java Utililty Methods List Max

List of utility methods to do List Max

Description

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

Method

intmaxIndex(List list)
Returns the index of the maximum element in the list, using the elements' natural ordering, or -1 if the list is empty.
if (list.isEmpty())
    return -1;
if (list.size() == 1)
    return 0;
int best = 0;
for (int i = 1; i < list.size(); ++i)
    if (list.get(i).compareTo(list.get(best)) > 0)
        best = i;
...
intmaxInnerSize(List> listOfLists)
Find the maximum size of the inner lists.
int result = 0;
for (Iterator<List<E>> it = listOfLists.iterator(); it.hasNext();) {
    List<E> list = it.next();
    int size = list.size();
    result = (size > result) ? size : result;
return result;
intmaxInt(List array)
max Int
if (array.size() == 0)
    return 0;
int res = array.get(0);
for (int i = 1; i < array.size(); i++) {
    res = Math.max(res, array.get(i));
return res;
intmaxLength(List patterns)
max Length
int len = Integer.MIN_VALUE;
for (char[] pattern : patterns) {
    if (pattern.length > len) {
        len = pattern.length;
return len;
intmaxLength(List list)
max Length
int result = 0;
for (String s : list) {
    result = Math.max(result, s.length());
return result;
intmaxLength(List strings)
max Length
int answer = 0;
for (String s : strings) {
    answer = Math.max(answer, s.length());
return answer;
ListmaxList(Iterable iterable)
Return a List containing all the elements of the specified Iterable that compare as being equal to the maximum element.
return maxList(iterable, new Comparator<T>() {
    public int compare(T o1, T o2) {
        return o1.compareTo(o2);
});
intmaxStringLength(List strings)
max String Length
int l = 0;
for (String s : strings)
    l = Math.max(l, s.length());
return l;