Java List sort via Stream

Description

Java List sort via Stream

import java.util.Arrays;
import java.util.List;

public class Main {
   public static void main(String[] args) {
      List<String> lst = Arrays.asList("CSS", "", "HTML", "Java", "Javascript", "demo2s.com");


      long count = lst.stream()
                      .sorted((String s1, String s2) -> {return s2.compareTo(s1);})
                      .limit(3)/* w w w  .jav a  2s .  com*/
                      .filter(s -> !s.isEmpty()).count();
      
      System.out.println(count);

   }
}



PreviousNext

Related