Java Array to String arrayToString(String[] strs)

Here you can find the source of arrayToString(String[] strs)

Description

Given an array of strings, return a comma-separated list of its elements.

License

Open Source License

Parameter

Parameter Description
strs Array of strings

Return

Empty string if strs.length is 0, comma separated list of strings otherwise

Declaration


public static String arrayToString(String[] strs) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w  ww  .  j av a 2  s. co  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();
    }
}

Related

  1. arrayToString(String[] str, char sep)
  2. arrayToString(String[] str, String separator)
  3. arrayToString(String[] stringArray)
  4. arrayToString(String[] stringArray)
  5. arrayToString(String[] strings)
  6. arrayToString(String[] strs)
  7. arrayToString(String[] strs, String separator)
  8. arrayToString(String[] theArray)
  9. ArrayToString(String[] values)