Java CSV String Create toCSVString(Object[] pStringArray)

Here you can find the source of toCSVString(Object[] pStringArray)

Description

Converts a string array to a string of comma-separated values.

License

Open Source License

Parameter

Parameter Description
pStringArray the string array

Return

A string of comma-separated values

Declaration

public static String toCSVString(Object[] pStringArray) 

Method Source Code

//package com.java2s;

public class Main {
    /**// ww  w. jav a 2s .c o m
     * Converts a string array to a string of comma-separated values.
     *
     * @param pStringArray the string array
     * @return A string of comma-separated values
     */
    public static String toCSVString(Object[] pStringArray) {
        return toCSVString(pStringArray, ", ");
    }

    /**
     * Converts a string array to a string separated by the given delimiter.
     *
     * @param pStringArray     the string array
     * @param pDelimiterString the delimiter string
     * @return string of delimiter separated values
     * @throws IllegalArgumentException if {@code pDelimiterString == null}
     */
    public static String toCSVString(Object[] pStringArray, String pDelimiterString) {
        if (pStringArray == null) {
            return "";
        }
        if (pDelimiterString == null) {
            throw new IllegalArgumentException("delimiter == null");
        }

        StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < pStringArray.length; i++) {
            if (i > 0) {
                buffer.append(pDelimiterString);
            }

            buffer.append(pStringArray[i]);
        }

        return buffer.toString();
    }
}

Related

  1. toCSV3_2(double[][][] array, int index1, int index3)
  2. toCSVBuffer(byte barr[])
  3. toCsvLine(final String[] parts)
  4. toCSVString(double[] d)
  5. toCsvString(Object object)
  6. toCSVString(String s)
  7. toCsvString(String text, char separator, char quote, String quoteEscaped)
  8. toCsvString(String text, String splitString, String replaceSplitChar)
  9. toCSVString(String[] fields)