Get largest String after sorting - Java java.lang

Java examples for java.lang:String Sort

Description

Get largest String after sorting

Demo Code


//package com.java2s;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Main {
    public static void main(String[] argv) {
        List strings = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(largestString(strings));
    }/* ww  w. j a  va 2s .c om*/

    public static int largestString(List<String> strings) {
        Comparator<String> length = new Comparator<String>() {
            public int compare(String left, String right) {
                return left.length() - right.length();
            }
        };
        return Collections.max(strings, length).length();
    }
}

Related Tutorials