Java-List转String、String转List

添加依赖

<dependency>
	<groupId>org.apache.commons</groupId>
	<artifactId>commons-lang3</artifactId>
	<version>3.7</version>
</dependency>

代码:

public static void main(String[] args) {
	List<String> list = new ArrayList<>();
	list.add("test1");
	list.add("test2");
	list.add("test3");
	String str = StringUtils.join(list.toArray(), ",");
	System.out.println("List转String:" + str);
	String str1 = "test4,test5,test6";
	List<String> result = Arrays.asList(str1.split(","));
	System.out.println("String转List:" + result);
}

执行结果:

List转String:test1,test2,test3
String转List:[test4, test5, test6]

文章仅作为个人学习整理

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页