当前位置:网站首页>List type to string type
List type to string type
2022-07-25 03:05:00 【Live learning programming ideas】
list Type transfer String type
Raise questions :
When deleting videos in batches , With List In the form of multiple videos id When it came in ,
This method request.setVideoIds(id); Parameters in can accept multiple :request.setVideoIds(id1,id2,id3,…);
So here comes the question , incoming List The parameters are like this :[id1,id2,id3] , How to handle List Turn into id1,id2,id3 In the form of
Method 1 : Use StringUtils.join() Method
1、 Ideas :
according to import org.apache.commons.lang3.StringUtils; Under this bag StringUtils.join() Method , Not traditional spring Medium
2、 Code display
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("11");
list.add("22");
list.add("33");
String join = StringUtils.join(list.toArray(), ",");
System.out.println(join);
}
result :
11,22,33
Learn programming ideas alive
3、 Source code analysis
You can't just use StringUtils.join() Method , And understand the principle , that ctrl+ left-click ( Click on join Method ) Look at the method source code :
public static String join(Object[] array, String separator) {
return array == null ? null : join((Object[])array, separator, 0, array.length);
}
public static String join(Object[] array, String separator, int startIndex, int endIndex) {
if (array == null) {
return null;
} else {
if (separator == null) {
separator = "";
}
int noOfItems = endIndex - startIndex;
if (noOfItems <= 0) {
return "";
} else {
StringBuilder buf = newStringBuilder(noOfItems);
if (array[startIndex] != null) {
buf.append(array[startIndex]);
}
for(int i = startIndex + 1; i < endIndex; ++i) {
buf.append(separator);
if (array[i] != null) {
buf.append(array[i]);
}
}
return buf.toString();
}
}
}
Specific description of source code
1、join() Method parameters are two , One is an array , One is
边栏推荐
- Arduino IDE for raspberry PI Pico development firmware localization installation tutorial
- The file in scanpy1.9.1 cannot be read in scanpy1.7.2. The problem is solved
- Resolve the error: org.apache.ibatis.binding.bindingexception
- Stm32cubemx quadrature encoder
- Web -- JDBC tool class writing
- Execution methods with static code blocks and child and parent classes
- Banana pie bpi-m5 toss record (2) -- compile u-boot
- Pypi counts the number of Downloads
- Use unicloud cloud function to decode wechat motion steps in applet
- Edit mathematical formulas in markdown
猜你喜欢

JS foundation -- math

Eslint error

Preliminary foundation JVM

Dc-2-range practice

Wechat sports field reservation of the finished works of the applet graduation project (6) opening defense ppt

Learning record 12

Brief understanding of operational amplifier

Learning record Xi

Use unicloud cloud function to decode wechat motion steps in applet

Beginners must see the markdown User Guide
随机推荐
Do you know about real-time 3D rendering? Real time rendering software and application scenarios are coming
Dc-2-range practice
Riotboard development board series notes (V) -- porting u-boot
JS written test question -- prototype, new, this comprehensive question
[jailhouse article] certify the uncertified rewards assessment of virtualization for mixed criticality
JS foundation -- hijacking of this keyword
Publish the project online and don't want to open a port
Domestic edge computing organization and product research
Get to know string thoroughly
Daily three questions 7.19
Mid year summary and personal feelings
Tp5.1 login configuration method of whether to login public functions (complete login case)
Use unicloud cloud function to decode wechat motion steps in applet
Dynamic planning of force buckle punch in summary
Print the common part of two ordered linked lists
Method of adding kernel in Jupiter notebook
Error: tomee required to support ear/ejb deployment
Solve the error: could not find 'xxxtest‘
Wechat sports field reservation of applet completion works applet graduation design (8) graduation design thesis template
Web -- JDBC tool class writing