Java Array to CSV arrayToCsvString(String[] array, char delimiter)

Here you can find the source of arrayToCsvString(String[] array, char delimiter)

Description

Utility method to convert a String array to CSV/TSV row string.

License

Open Source License

Parameter

Parameter Description
array String array to be converted
delimiter Delimiter to be used (comma for CSV tab for TSV)

Return

CSV/TSV row string

Declaration

public static String arrayToCsvString(String[] array, char delimiter) 

Method Source Code

//package com.java2s;
/*/*from   w  w w .  j  a  v  a 2s.  c  o m*/
 * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

public class Main {
    /**
     * Utility method to convert a String array to CSV/TSV row string.
     *
     * @param array String array to be converted
     * @param delimiter Delimiter to be used (comma for CSV tab for TSV)
     * @return CSV/TSV row string
     */
    public static String arrayToCsvString(String[] array, char delimiter) {
        StringBuilder arrayString = new StringBuilder();
        for (String arrayElement : array) {
            arrayString.append(arrayElement);
            arrayString.append(delimiter);
        }
        return arrayString.toString();
    }
}

Related

  1. ArrayToCsv(Object[] line)
  2. ArrayToCSV(String[] array)
  3. toCSV(double[] as)
  4. toCSV(int[][] values)
  5. toCSV(Object[] objs)
  6. toCSVString(String[] strArray)