Java Arrays sort array via Stream

Description

Java Arrays sort array via Stream



import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
   public static void main(String[] args) {
      String[] array = {"CSS", "", "HTML", "Java", "Javascript", "demo2s.com"};

       List<String> list= Arrays.stream(array)
                  .filter(s -> s.compareToIgnoreCase("Java") > 0)
                  .sorted(String.CASE_INSENSITIVE_ORDER.reversed())
                  .collect(Collectors.toList());
       //w w w  .j a  va2  s .  c o m
       System.out.println("strings greater than m sorted descending:"+list);

   }
}



PreviousNext

Related