Java List join to String via Stream

Description

Java List join to String 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");


      String str = lst.stream().filter(s -> !s.isEmpty()).collect(Collectors.joining(","));
      System.out.println(str);/*from  w  w w.j av  a 2 s.  c  om*/

   }
}



PreviousNext

Related