StringUtils.join方法总结

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
List list=new ArrayList();
list.add("a");
list.add("b");
list.add("c");
String listjoin=StringUtils.join(list);
String listjoin2=StringUtils.join(list,",");
System.out.println(listjoin);
System.out.println(listjoin2);

StringBuffer sb=new StringBuffer();
sb.append("x,y,z,");
String arrjoin=StringUtils.join(sb.toString().split(","));
String arrjoin2=StringUtils.join(sb.toString().split(","),",");

System.out.println(arrjoin);
System.out.println(arrjoin2);

输出结果:

[a, b, c]
a,b,c
xyz
x,y,z

你可能感兴趣的:(java)