Java CSV from toCsv(final List list)

Here you can find the source of toCsv(final List list)

Description

Convert List of strins to csv

License

Apache License

Parameter

Parameter Description
list List to be converted. Optimistic code, the strings on the list should <b>not</b> contain <b>;</b>

Return

String separated by ;

Declaration

public static String toCsv(final List<String> list) 

Method Source Code

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

import java.util.List;

public class Main {
    /**/* www.  ja  v  a2  s  .c  o  m*/
     * Convert List of strins to csv
     * @param list List to be converted. Optimistic code, the strings on the list
     *             should <b>not</b> contain <b>;</b>
     * @return String separated by ;
     */
    public static String toCsv(final List<String> list) {
        return toString(list, ';');
    }

    /**
     * Convert a list of strings to a string separated by delimiter
     * @param list List
     * @param delimiter Delimiter
     * @return String
     */
    public static String toString(final List<String> list, char delimiter) {
        final StringBuilder b = new StringBuilder();
        if (list != null) {
            for (int i = 0; i < list.size(); i++) {
                b.append(list.get(i));
                if (i != list.size() - 1) {
                    b.append(delimiter);
                }
            }
        }
        return b.toString();
    }
}

Related

  1. listToCSVString(List list)
  2. listToCsvTags(List tagsList)
  3. parseCSVList(String csv)
  4. parseCsvList(String csvList)
  5. sanitizeListForCsv(List strList)
  6. toCsv(List list)
  7. toCsv(List list)
  8. toCsv(List strs)
  9. toCSV(List list)