Stream流合并字符串、拼接字符串

 

List strings = Arrays.asList("abc", "", "de", "efg", "abcd", "", "jkl");

String mergeString = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.joining(","));

System.err.println("合并字符串 : "+mergeString);

控制台输出

合并字符串 : abc,de,efg,abcd,jkl

.stream 将数据转换成stream流

.filter 过滤字段

Collectors.joining 字符串连接收集器(字符串拼接)

你可能感兴趣的:(Stream流)