Java CSV from toCsvString(List values)

Here you can find the source of toCsvString(List values)

Description

to Csv String

License

Open Source License

Declaration

public static String toCsvString(List<String> values) 

Method Source Code

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

import java.util.List;

public class Main {
    public static String toCsvString(List<String> values) {

        String csvString = toDelimitedString(values, ",", true);

        return csvString;
    }/*  w w  w  .j ava 2s . co m*/

    public static String toDelimitedString(List<String> values, String delimiter, boolean trimValues) {

        if (values == null || delimiter == null) {
            return null;
        }

        StringBuilder stringBuilder = new StringBuilder();

        for (int index = 0; index < values.size(); index++) {
            String value = values.get(index);

            String valueToUse = value;
            if (trimValues) {
                valueToUse = valueToUse.trim();
            }

            if (index > 0) {
                stringBuilder.append(delimiter);
            }

            stringBuilder.append(valueToUse);
        }

        String delimitedString = stringBuilder.toString();

        return delimitedString;

    }
}

Related

  1. toCsv(List strs)
  2. toCSV(List list)
  3. toCSV(Set list)
  4. toCSVLine(String[] strArray)
  5. toCSVString(List list, boolean quote)
  6. toCsvString(List values)
  7. toCSVString(List values, boolean[] quoteColumn, String fieldSeparator, String quotationChar)
  8. toObjectList(String csvString)