Java ArrayList to CSV toCsvRow(ArrayList csvRow)

Here you can find the source of toCsvRow(ArrayList csvRow)

Description

to Csv Row

License

Apache License

Declaration

public static String toCsvRow(ArrayList<String> csvRow) 

Method Source Code

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

import java.util.ArrayList;

public class Main {
    public static String toCsvRow(ArrayList<String> csvRow) {
        StringBuilder csvStringBuilder = new StringBuilder();
        makeCsvRow(csvRow, csvStringBuilder);
        return csvStringBuilder.toString();
    }/* w  w w .  ja v  a  2s  .  c om*/

    private static void makeCsvRow(ArrayList<String> row, StringBuilder csvStringBuilder) {
        String fieldDelim = "";
        for (Object fieldObj : row.toArray()) {
            String field = fieldObj.toString();
            field = field.replaceAll("\"", "\"\"");
            csvStringBuilder.append(fieldDelim).append("\"").append(field).append("\"");
            fieldDelim = ",";
        }
    }
}

Related

  1. toCsv(ArrayList columnVectors)
  2. ToCSV(ArrayList vals)