当前位置:网站首页>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 language and SQL Server database technology
- English语法_不定代词 - other / another
- Idea error failed to determine a suitable driver class
- 阿里云技术专家邓青琳:云上跨可用区容灾和异地多活最佳实践
- 转载----如何阅读代码?
- Ten common application scenarios of redis
- Jqgrid select all cancel single line click cancel event
- Copy files / folders through Robocopy
- Yes, UDP protocol can also be used to request DNS server
- I hope some suggestions on SQL optimization can help you who are tortured by SQL like me
猜你喜欢

Alibaba cloud installs mysql5.7

SQL优化的一些建议,希望可以帮到和我一样被SQL折磨的你

Melodic + Realsense D435i 配置及错误问题解决

41 picture background synthesis - colorful navigation map

阿里云安装MYSQL5.7

I hope some suggestions on SQL optimization can help you who are tortured by SQL like me

直播课堂系统05-后台管理系统

51单片机学习笔记(1)

Gonzalez Digital Image Processing Chapter 1 Introduction

LeetCode-198-打家劫舍
随机推荐
41 图片背景综合-五彩导航图
C language and SQL Server database technology
LeetCode_字符串_中等_151.颠倒字符串中的单词
Gson and fastjson
Gameframework making games (I)
Overview of cloud security technology development
Resource not found: rgbd_ Launch solution
The main function of component procurement system, digital procurement helps component enterprises develop rapidly
Software testing -- 1. Outline of software testing knowledge
Gonzalez Digital Image Processing Chapter 1 Introduction
06. Neural network like
35 quick format code
32 chrome调试工具的使用
Realsense-Ros安装配置介绍与问题解决
D2. Chopping Carrots (Hard Version) (每日一题)
Idea error failed to determine a suitable driver class
IP address classification, which determines whether a network segment is a subnet supernetwork
45padding不会撑开盒子的情况
Qt connect 中, SIGNAL,SLOT 与 lambda 对比
冈萨雷斯 数字图像处理 第一章绪论