如何相互转换逗号分隔的字符串和List
展开全部
方法 1: 利用JDK的Arrays类
[java] view plain copy
ico_fork.svg
1.5 KB
String str = "a,b,c";
List<String> result = Arrays.asList(str.split(","));
方法 2: 利用Guava的Splitter
[java] view plain copy
ico_fork.svg
1.5 KB
String str = "a, b, c";
List<String> result = Splitter.on(",").trimResults().splitToList(str);
方法 3: 利用Apache Commons的StringUtils (只是用了split)
[java] view plain copy
ico_fork.svg
1.5 KB
String str = "a,b,c";
List<String> result = Arrays.asList(StringUtils.split(str,","));
[java] view plain copy
ico_fork.svg
1.5 KB
String str = "a,b,c";
List<String> result = Arrays.asList(str.split(","));
方法 2: 利用Guava的Splitter
[java] view plain copy
ico_fork.svg
1.5 KB
String str = "a, b, c";
List<String> result = Splitter.on(",").trimResults().splitToList(str);
方法 3: 利用Apache Commons的StringUtils (只是用了split)
[java] view plain copy
ico_fork.svg
1.5 KB
String str = "a,b,c";
List<String> result = Arrays.asList(StringUtils.split(str,","));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询