日期:2014-05-17 浏览次数:20678 次
import java.util.ArrayList; import java.util.List; public class StringBuilderDemo1 { public static String join(String join,String[] strAry){ StringBuffer sb=new StringBuffer(); for(int i=0;i<strAry.length;i++){ if(i==(strAry.length-1)){ sb.append(strAry[i]); }else{ sb.append(strAry[i]).append(join); } } return new String(sb); } public static void main(String[] args){ String[] sa={"a","b","c"}; String s1=StringBuilderDemo1.join("-",sa); System.out.println(s1); } }
------解决方案--------------------
Apache Commons组件中有一个commons-lang.jar,用StringUtils.join(array, "-")就可以了,我经常用