Java Array to String convertArrayToString(String[] array)

Here you can find the source of convertArrayToString(String[] array)

Description

converts the specified String array to a token String.

License

LGPL

Parameter

Parameter Description
array to be converted array

Return

converted token String

Declaration

public static String convertArrayToString(String[] array) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**/*w ww . j a va 2  s .co  m*/
     * converts the specified <code>String</code> array to a token <code>String</code>.
     * the token is a char ','. if <code>array</code> is <code>null</code> or zeor length,
     * return an empty <code>String</code>; if the element in the <code>array</code> is <code>null</code> or empty
     * <code>String</code>, ignores this element.
     * 
     * @param array
     *            to be converted array
     * @return converted token <code>String</code>
     * @author sunf
     * @since AP.308
     */
    public static String convertArrayToString(String[] array) {
        if (array == null || array.length == 0) {
            return "";
        }
        final char token = ',';
        StringBuffer result = new StringBuffer();

        for (int i = 0, size = array.length; i < size; i++) {
            if (array[i] == null || array[i].length() == 0) {
                continue;
            }
            result.append(array[i]);
            result.append(token);
        }
        // deletes the last char of \'
        if (result.length() > 1) {
            result.deleteCharAt(result.length() - 1);
        }

        return result.toString();
    }
}

Related

  1. convertArrayToString(double[] p)
  2. convertArrayToString(Object param)
  3. convertArrayToString(Object[] array, String separator)
  4. convertArrayToString(Object[] ig, int count)
  5. convertArrayToString(Object[] objArr)
  6. convertArrayToString(String[] array, char seperator)
  7. convertArrayToString(String[] array, String separator)
  8. convertArrayToString(String[] array, String separator)
  9. convertArrayToString(String[] fields, String delimiter)