Here you can find the source of maxLength(Collection
Parameter | Description |
---|---|
strings | Collection of String ; may not be null |
public static int maxLength(Collection<String> strings)
//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; } }