当前位置:网站首页>拼接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()…….;
边栏推荐
- JS基础6
- [unity][ecs] learning notes (III)
- 港伦敦金行情走势图所隐藏的信息
- Décompression par compression
- OpenHarmony应用开发之二维码生成器
- Secretary of the Ukrainian national security and National Defense Commission: will carry out precision strikes against targets in Russia
- To enhance the function of jupyter notebook, here are four tips
- 【LeetCode每日一题】【2021/12/19】997. 找到小镇的法官
- Realization of a springboard machine
- How does ETF position affect spot gold price?
猜你喜欢

An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!
![[Unity]EBUSY: resource busy or locked](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[Unity]EBUSY: resource busy or locked

【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)

Katalon当中的debug调试

满电出发加速品牌焕新,长安电动电气化产品吹响“集结号”

Interface automation framework scaffold - use reflection mechanism to realize the unified initiator of the interface

Remote connection of raspberry pie in VNC viewer mode without display

Threads and thread pools

JS基础1-JS引入与运算符

【monkey】monkey测试入门
随机推荐
Katalon当中的output使用方法
[unity][ecs] learning notes (III)
一种跳板机的实现思路
物联网无线通信应用中6种融合定位技术
An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!
MytipartFile与File的相互转换
Dataease installation upgrade
Yann Lecun's new paper: the road to building automatic agents
[QT] connect syntax reference implementation
Pop up and push in sequence of stack < difficulty coefficient >
MySQL general binary installation method
Ble Bluetooth module nrf518/nrf281/nrf528/nrf284 chip scheme comparison
JS基础1-JS引入与运算符
[NLP] this year's college entrance examination English AI score is 134. The research of Fudan Wuda alumni is interesting
Fabric. How to use js brush?
Mysql通用二进制安装方式
Realize an air conditioner with compose to bring you cool in summer
如何使用 DataAnt 监控 Apache APISIX
【Qt】connect 语法参考实现
Mongo database