java 8 streams
package net.sness;import java.util.*;
import java.util.stream.Stream;public class TestMax {
public static void main(String[] args) {Collection<String> strings = Arrays.asList("one", "two", "three");
Optional<String> longest = strings.stream()
.max(Comparator.comparingInt(String::length));System.out.println("longest=" + longest.get());
}
}