当前位置:网站首页>Splice a field of the list set into a single string
Splice a field of the list set into a single string
2022-07-25 14:51:00 【Zanzaner_】
take list A field of the set splices a single String
Yes 2 Methods
- loop (lambad Expression method )
- Recursively, the list A field of the set splices a single String
List<Employee> emps = Arrays.asList(
new Employee(102, " Li Si ", 59, 6666.66, Employee.Status.BUSY),
new Employee(101, " Zhang San ", 18, 9999.99, Employee.Status.FREE),
new Employee(103, " Wang Wu ", 28, 3333.33, Employee.Status.VOCATION)
);
// take list A field of the set splices a single String
@Test
public void testList(){
if(emps != null && emps.size() >=0){
// The first 1 Kind of lambad Expression method
String s= emps.stream().map(p->p.getName()).collect(Collectors.joining(","));
System.out.println(s);
// The first 2 Kind of Recursively, the list A field of the set splices a single String
String loopJoint = loopJointASC(emps, emps.size());
System.out.println(loopJoint);
}
}
public static String loopJointASC(List<Employee> list, int size) {
if(list.size()<=0) return null;
if(size==1) return list.get(list.size()-1).getName();
String joinStr = ",";
String name = list.get(list.size()-size).getName();
size--;// Subscript value and recursion number decrease 1
String loopJoint = loopJointASC(list, size);
return name+joinStr+loopJoint;
}
Running results 
边栏推荐
- [C题目]力扣88. 合并两个有序数组
- Syntax summary of easygui
- Awk from getting started to digging in (23) awk built-in variables argc, argc -- command line parameter transfer
- PHP implements non blocking (concurrent) request mode through native curl
- Thymeleaf controls whether display is displayed through style
- IP地址分类,判断一个网段是子网超网
- GameFramework制作游戏(一)
- gson与fastjson
- EDA chip design solution based on AMD epyc server
- Gameframework making games (II) making UI interface
猜你喜欢
![[MySQL series] - how much do you know about the index](/img/d7/5045a846580be106e2bf16d7b30581.png)
[MySQL series] - how much do you know about the index

51 single chip microcomputer learning notes (2)
![Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]](/img/b6/62a346174bfa63fe352f9ef7596bfc.png)
Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]

Melody + realsense d435i configuration and error resolution

阿里云安装MYSQL5.7

Gameframework making games (I)

45padding不会撑开盒子的情况

Idea error failed to determine a suitable driver class

【MySQL系列】-索引知多少

006 operator introduction
随机推荐
C language and SQL Server database technology
软件测试 -- 1 软件测试知识大纲梳理
Paddlenlp之UIE关系抽取模型【高管关系抽取为例】
变分(Calculus of variations)的概念及运算规则
44 Sina navigation, Xiaomi sidebar exercise
51单片机学习笔记(1)
SQL优化的一些建议,希望可以帮到和我一样被SQL折磨的你
awk从入门到入土(24)提取指令网卡的ip
39 简洁版小米侧边栏练习
Realsense ROS installation configuration introduction and problem solving
Practical guide for network security emergency response technology (Qianxin)
国联证券买股票开户安全吗?
转载----如何阅读代码?
[C题目]力扣206. 反转链表
Gateway reports an error service_ UNAVAILABLE
QT connect, signal, slot and lambda comparison
easygui使用的语法总结
Ten common application scenarios of redis
物理量与单位符号的书写标准
How many ways can you assign initial values to a two-dimensional array?