Java List filter empty element via Stream

Description

Java List filter empty element via Stream

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

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

      List<String> lstWithoutEmptyRec = 
            lst.stream()//from   w w  w.  j a v  a  2  s . c om
               .filter(s -> !s.isEmpty())
               .collect(Collectors.toList());

      System.out.println(lstWithoutEmptyRec);
   }
}



PreviousNext

Related