日期:2014-05-20  浏览次数:20638 次

有没函数将 String[] mystr 假设由3个元素,连接成一个字符串,逗号分隔
有没函数将   String[]   mystr   假设由3个元素,连接成一个字符串,逗号分隔

------解决方案--------------------
String[] s = { "aa ", "bb ", "cc "};
String str = Arrays.toString(s).replaceAll( "\\[|\\] ", " ");
System.out.println(str);
------解决方案--------------------
apache组织实现的commons-lang组件(下载地址http://jakarta.apache.org/commons/lang/)中的StringUtils就可以。具体使用如下:
String str[]=new String[]{ "a ", "b ", "c "};
System.out.println(StringUtils.join(str, ', '));
输出结果为:a,b,c
不知道是不是你想要的结果。

------解决方案--------------------
String[] s = { "aa ", "bb ", "cc "};
Matcher m = Pattern.compile( "(\\w+,\\s){2}\\w+ ").matcher(Arrays.toString(s));
if(m.find())
System.out.println(m.group());
来个无聊点的,稍微复杂了点,没一楼的简洁