0){sb.append(",");}sb"/> 0){sb.append(",");}sb">
通常会这么写:
public static void main(String[] args) { String strs = ""; String[] arr = new String[]{"aa", "cc", "bb"}; // 转换前的字符串数组 StringBuilder sb = new StringBuilder(); for (String ele : arr) { if (sb.length() > 0) { sb.append(","); } sb.append(ele); } strs = sb.toString(); // 转换后的逗号分隔字符串 System.out.println(strs); }
更简单的写法:
public static void main(String[] args) { String[] arr = new String[]{"aa", "cc", "bb"}; // 转换前的字符串数组 String strs = String.join(",", arr); // 转换后的逗号分隔字符串 System.out.println(strs); }
以上是Java中如何将字符串数组转换为逗号分隔的字符串的详细内容。更多信息请关注PHP中文网其他相关文章!