Here you can find the source of arrayToString(String[] strs)
Parameter | Description |
---|---|
strs | Array of strings |
public static String arrayToString(String[] strs)
//package com.java2s; public class Main { /**/*from w ww. j a v a 2s .c o m*/ * Given an array of strings, return a comma-separated list of its elements. * * @param strs * Array of strings * @return Empty string if strs.length is 0, comma separated list of strings otherwise */ public static String arrayToString(String[] strs) { if (strs.length == 0) { return ""; } StringBuffer sbuf = new StringBuffer(); sbuf.append(strs[0]); for (int idx = 1; idx < strs.length; idx++) { sbuf.append(","); sbuf.append(strs[idx]); } return sbuf.toString(); } public static String toString(String[] content, String sign) { if (null == content) { return null; } sign = null == sign ? "," : sign; StringBuilder strBuilder = new StringBuilder(); for (int i = 0; i < content.length; i++) { strBuilder.append(content[i]); if (i < content.length - 1) { strBuilder.append(sign); } } return strBuilder.toString(); } }