Java Collection Max maxLength(Collection strings)

Here you can find the source of maxLength(Collection strings)

Description

Returns the max String length from a Collection .

License

Apache License

Parameter

Parameter Description
strings Collection of String ; may not be null

Return

int max length

Declaration

public static int maxLength(Collection<String> strings) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**/* w  w  w  . ja  v a 2  s  . c o  m*/
     * Returns the max {@link String} length from a {@link Collection}.
     *
     * @param strings {@link Collection} of {@link String}; may not be
     * {@code null}
     * @return {@code int} max length
     */
    public static int maxLength(Collection<String> strings) {
        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();
                if (l > max) {
                    max = l;
                }
            }
        }
        return max;
    }
}

Related

  1. max(Collection elems)
  2. max(Collection values)
  3. max(Collection values)
  4. max(final Collection values)
  5. max(final Collection collection)
  6. maxOr(Collection values, T defaultVal)
  7. minOrMax(int sign, Collection values)
  8. partitionFixed(int maxNumChunks, Collection coll)
  9. toString(Collection collection, int maxLen)