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中文網其他相關文章!