Java CSV from listToCsv(List strs)

Here you can find the source of listToCsv(List strs)

Description

list To Csv

License

Apache License

Declaration

public static String listToCsv(List<String> strs) 

Method Source Code


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

import java.util.List;

public class Main {
    private static final String COMMA = ",";
    private static final String QUOTE = "\"";

    public static String listToCsv(List<String> strs) {
        return doListToCsv(strs);
    }/*from   w w w . ja va  2s .  co  m*/

    private static <T> String doListToCsv(List<T> list) {
        if (list == null) {
            return "";
        }

        StringBuilder csv = new StringBuilder();
        boolean first = true;
        for (T element : list) {
            if (first) {
                first = false;
            } else {
                csv.append(COMMA);
            }
            csv.append(QUOTE).append(element == null ? "" : element).append(QUOTE);
        }
        return csv.toString();
    }
}

Related

  1. getStringList(String csv)
  2. getStringListFromCsv(String tags)
  3. getVendorIdsAndNames(String vendorCsv, List vendorNames, List vendorIDs)
  4. listToCsv(List list)
  5. listToCsv(List listOfStrings, char separator)
  6. ListtoCSV(List thelist, String sep)
  7. listToCSVString(List list)
  8. listToCsvTags(List tagsList)
  9. parseCSVList(String csv)