当前位置:网站首页>拼接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()…….;
边栏推荐
猜你喜欢
随机推荐
DlhSoft Kanban Library for WPF
Training and recognition of handwritten digits through the lenet-5 network built by pytorch
Mysql database overview and installation process
2022 Wu Enda machine learning specialization week 2 practice lab: linear expression
【功能建议】多个工作空间启动时选择某个空间
Who knows if it is safe to open an account with CSC securities
JS基础6
linux中源码安装mysql数据库(centos)
Internet of things application case of wireless module transparent transmission technology
Redis数据库
Yann Lecun's new paper: the road to building automatic agents
BLE蓝牙模块NRF518/NRF281/NRF528/NRF284芯片方案对比
Metersphere uses JS to refresh the current page
Secretary of the Ukrainian national security and National Defense Commission: will carry out precision strikes against targets in Russia
Does flink1.15 support MySQL views? I configured the view name at the table name to save, but the table could not be found. Think
MySQL (II)
Décompression par compression
JSON module, hashlib, Base64
Metersphere实现UI自动化元素不可点击(部分遮挡)
Pop up and push in sequence of stack < difficulty coefficient >
![[unity] built in rendering pipeline to URP](/img/a5/3ae37b847042ffb34e436720f61d17.png)







![[practice] appium settings app is not running after 5000ms](/img/3c/5a7544561231a15a4bb5cfa9e102b3.png)
