当前位置:网站首页>Splicing strings in the string collection_ Stream based
Splicing strings in the string collection_ Stream based
2022-06-28 11:02:00 【Hello_ xzy_ Word】
Splicing String String in collection
Existing string collection “ Zhang San ” 、“ Li Si ” 、“ Wang Wu ”、“”、null, Now you need to separate the strings in the collection with commas , Concatenate into a string .
public class Main2 { public static void main(String[] args) { Set<String> studentNameSet = new HashSet<>(5); studentNameSet.add(" Zhang San "); studentNameSet.add(" Li Si "); studentNameSet.add(" Wang Wu "); studentNameSet.add(""); studentNameSet.add(null); String studentNameString = studentNameSet .stream() .filter(name -> name != null && name.length() > 0) .collect(Collectors.joining(",")); System.out.println(studentNameString); } }Output results :
Li Si , Zhang San , Wang WuBe careful :
- Use filters to filter invalid data ;
- Filter can be connected :filter().filter().filter()…….;
边栏推荐
- MySQL (III)
- [monkey] Introduction to monkey test
- 东方财富手机股票开户哪个券商更安全更方便?
- Katalon当中的output使用方法
- [practice] 1364- implement a perfect waterfall flow component on the mobile terminal (with source code)
- MySQL(三)
- Bytecode proof in appliedzkp zkevm (9)
- [Li Kou - dynamic planning] sort out topic 1: basic topics: 509, 70, 746, 62, 63, 343, 96 (with links, topic descriptions, problem solving methods and codes)
- Yann LeCun新论文:构建自动智能体之路
- 毕业季,给初入社会的你一些建议
猜你喜欢
随机推荐
JSON module, hashlib, Base64
Guangzhou Customs supports the stable supply of food, agricultural products, traditional Chinese medicine and other civilian and biological resources to Hong Kong
还在用 SimpleDateFormat 做时间格式化?小心项目崩掉!
Remote connection of raspberry pie in VNC viewer mode without display
字符串 & 堆 & 方法区
MySQL (II)
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
File的io流与base64
Fastposter v2.8.4 release e-commerce poster generator
Dataease installation upgrade
Ble Bluetooth module nrf518/nrf281/nrf528/nrf284 chip scheme comparison
JS基础8
[cloud resident co creation] detailed introduction to DWS alarm service DMS and cluster connection mode
Spatial-Temporal时间序列预测建模方法汇总
静态库的制作和使用
Katalon当中的使用循环for、while和if...else、break、continue
Datetime and logging module
Katalon global variable is referenced in testobject
MySQL(二)
SQL必需掌握的100个重要知识点:检索数据








