Java CSV from convertStringListToCSV(List source)

Here you can find the source of convertStringListToCSV(List source)

Description

convert String List To CSV

License

Open Source License

Declaration

public static String convertStringListToCSV(List<String> source) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.List;

public class Main {
    public static String convertStringListToCSV(List<String> source) {
        String finalString = "";
        if (source != null && !source.isEmpty()) {
            for (String s : source) {
                if (s != null) {
                    finalString = finalString.isEmpty() ? finalString + getValidCsvValue(s)
                            : finalString + "," + getValidCsvValue(s);
                }/*from   w w  w .j av a 2  s.c  o  m*/
            }
        }
        return finalString;
    }

    public static String getValidCsvValue(String value) {
        if (value.contains(",")) {
            value = "\"" + value + "\"";
        }
        return value;
    }
}

Related

  1. addAllFromCSV(List list, String csv)
  2. convertListToCSVString(List itemsList)
  3. convertListToCSVString(List list)
  4. convertStringListToCSV(List inputStringList)
  5. countMaxColumnSizeByArray(List csvs)
  6. csv2list(String csvString)
  7. csvList(String _text, Integer[] _idx_ret)
  8. csvTagsToList(String tags)