一、String转List
使用Hutool工具类Convert
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.16</version>
</dependency>
public class Client {
public static void main(String[] args) {
String strs = "a,b,c,d";
List<String> strList = Convert.toList(String.class,strs);
//4
System.out.println(strList.size());
//[a, b, c, d]
System.out.println(strList);
}
}
二、List转String
使用JDKStringUtils
工具类,逗号拼接成字符串
public static void main(String[] args) {
List<String> strList = new ArrayList<String>();
strList.add("a");
strList.add("b");
strList.add("c");
strList.add("d");
String strs = StringUtils.join(strList,",");
//a,b,c,d
System.out.println(strs);
}
使用Hutool工具类Convert
,数组类型
public static void main(String[] args) {
List<String> strList = new ArrayList<String>();
strList.add("a");
strList.add("b");
strList.add("c");
strList.add("d");
String strs = Convert.toStr(strList);
//[a, b, c, d] 数组类型
System.out.println(strs);
}
网友评论