java中逗号分隔的字符串和List相互转换

时间:2025-04-21 08:02:23

1、将逗号分隔的字符串转换为List

String str = "a,b,c";  

List<String> result = ((","));

2、将List转换为逗号分隔的字符串

(1) 利用Guava的Joiner

List<String> list = new ArrayList<String>();  
("a");  
("b");  
("c");  

String str = (",").join(list);  

(2)利用Apache Commons的StringUtils

List<String> list = new ArrayList<String>();  
("a");  
("b");  
("c");  

String str = ((), ",");  

原文:/hui-blog/p/