Here you can find the source of convertArrayToString(String[] array)
String
array to a token String
.
Parameter | Description |
---|---|
array | to be converted array |
String
public static String convertArrayToString(String[] array)
//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(); } }