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

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

String str = "a,b,c";  

List result = Arrays.asList(str.split(","));

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

(1) 利用Guava的Joiner

List list = new ArrayList();  
list.add("a");  
list.add("b");  
list.add("c");  

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

(2)利用Apache Commons的StringUtils

List list = new ArrayList();  
list.add("a");  
list.add("b");  
list.add("c");  

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

原文:https://www.cnblogs.com/hui-blog/p/6375174.html

你可能感兴趣的:(java中逗号分隔的字符串和List相互转换)