Java List get top element after sort()
via Stream
import java.util.Arrays; import java.util.List; import java.util.Optional; public class Main { public static void main(String[] args) { List<String> lst = Arrays.asList("CSS", "", "HTML", "Java", "Javascript", "demo2s.com"); Optional<String> c= lst.stream() .sorted((String s1, String s2) -> {return s2.compareTo(s1);}) .limit(1)//from w w w . ja v a 2 s . c o m .findFirst(); System.out.println(c); } }