当前位置:网站首页>拼接String集合中的字符串_基于Stream
拼接String集合中的字符串_基于Stream
2022-06-28 10:51:00 【Hello_xzy_Word】
拼接String集合中的字符串
现有字符串集合 “张三” 、“李四” 、“王五”、“”、null,现需要将集合中的字符串以逗号隔开,拼接成一个字符串。
public class Main2 { public static void main(String[] args) { Set<String> studentNameSet = new HashSet<>(5); studentNameSet.add("张三"); studentNameSet.add("李四"); studentNameSet.add("王五"); studentNameSet.add(""); studentNameSet.add(null); String studentNameString = studentNameSet .stream() .filter(name -> name != null && name.length() > 0) .collect(Collectors.joining(",")); System.out.println(studentNameString); } }输出结果:
李四,张三,王五注意:
- 使用过滤器对无效数据进行过滤;
- 过滤器可进行连接:filter().filter().filter()…….;
边栏推荐
- Who knows if it is safe to open an account with CSC securities
- Sqlcmd database connection error
- The boss asked me to write an app automation -- yaml file reading -- with the whole framework source code attached
- 【agora】get 一个 agora_refptr 对象的用法示例
- MySQL (I)
- Ribbon核心源码解析
- MySQL(三)
- MySQL(二)
- Redis数据库
- JS基础1-JS引入与运算符
猜你喜欢

Mysql database overview and installation process

How does ETF position affect spot gold price?
![[practice] appium settings app is not running after 5000ms](/img/3c/5a7544561231a15a4bb5cfa9e102b3.png)
[practice] appium settings app is not running after 5000ms

还在用 SimpleDateFormat 做时间格式化?小心项目崩掉!

Fastposter v2.8.4 release e-commerce poster generator

DlhSoft Kanban Library for WPF
![[unity][ecs] learning notes (I)](/img/eb/1f0ad817bbc441fd8c14d046b82dd0.png)
[unity][ecs] learning notes (I)

Yann Lecun's new paper: the road to building automatic agents
![[monkey] Introduction to monkey test](/img/70/5a7152d0b6b77df7f9d6ad0e09e000.png)
[monkey] Introduction to monkey test

MySQL general binary installation method
随机推荐
[leetcode daily question] [December 19, 2021] 997 Find the town judge
Datetime and logging module
Yann Lecun's new paper: the road to building automatic agents
关于FTP的协议了解
[QT] connect syntax reference implementation
港伦敦金行情走势图所隐藏的信息
[Unity]EBUSY: resource busy or locked
2022 Wu Enda machine learning specialization week 2 practice lab: linear expression
[function suggestion] select a space when multiple workspaces are started
还在用 SimpleDateFormat 做时间格式化?小心项目崩掉!
Markdown -- basic usage syntax
物联网5种无线传输协议特点大汇总
Remote connection of raspberry pie in VNC viewer mode without display
sentinel
Understand 12 convolution methods (including 1x1 convolution, transpose convolution and deep separable convolution)
【力扣——动态规划】整理题目1:基础题目:509、70、746、62、63、343、96(附链接、题目描述、解题方法及代码)
Ribbon核心源码解析
Summary of characteristics of five wireless transmission protocols of Internet of things
Wireless communication module fixed-point transmission - point to multipoint specific transmission application
fastposter v2.8.4 发布 电商海报生成器