将List<String>转字符串

 

4.使用第三方库

下面将看到使用Apache Commons的StringUtils类来实现类似的结果。

4.1Maven Dependency

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

可以在此处找到最新版本的依赖项。

4.2实现

该实现实际上是单个方法调用:

 @Test
 public  void  whenStringUtilsJoin_thenPrintCustom() {
	List intList = Arrays.asList(1,2,3);
	System.out.println(StringUtils.join(intList,"|"));

 }

输出:

  1|2|3



https://www.chendalei.com/java-list-to-string.html
posted @ 2021-07-06 21:53  wq9  阅读(398)  评论(0)    收藏  举报