Java CSV from convertListToCSVString(List itemsList)

Here you can find the source of convertListToCSVString(List itemsList)

Description

convert List To CSV String

License

Open Source License

Declaration

public static String convertListToCSVString(List<Long> itemsList) 

Method Source Code

//package com.java2s;
/**//from www  .ja va2  s.c om
 * Copyright (c) 2012 Salil Walavalkar
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 
 * subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial 
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 
 * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import java.util.List;

public class Main {
    /**
     * Comma separator.
     */
    public static final String COMMA_SEPARATOR = ",";

    public static String convertListToCSVString(List<Long> itemsList) {
        StringBuilder csvString = new StringBuilder();
        if (itemsList != null && !itemsList.isEmpty()) {
            for (Long item : itemsList) {
                if (csvString.length() > 0) {
                    csvString.append(COMMA_SEPARATOR);
                    csvString.append(item.toString());
                } else {
                    csvString.append(item.toString());
                }
            }
        }
        return csvString.toString();
    }
}

Related

  1. addAllFromCSV(List list, String csv)
  2. convertListToCSVString(List list)
  3. convertStringListToCSV(List inputStringList)
  4. convertStringListToCSV(List source)
  5. countMaxColumnSizeByArray(List csvs)