Java CSV File Parse parseCSV(String csv)

Here you can find the source of parseCSV(String csv)

Description

Parses a CSV string into a list of strings, removing spaces and empty strings

License

Open Source License

Parameter

Parameter Description
csv the string

Return

the list of strings

Declaration

public static List<String> parseCSV(String csv) 

Method Source Code

//package com.java2s;
/**//from  w w w  .jav  a  2s .co m
 * Copyright 2011 Rowan Seymour
 * 
 * This file is part of Kumva.
 *
 * Kumva is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Kumva is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Kumva. If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Parses a CSV string into a list of strings, removing spaces and empty strings
     * @param csv the string
     * @return the list of strings
     */
    public static List<String> parseCSV(String csv) {
        String[] vals = csv.split(",");
        List<String> strs = new ArrayList<String>();
        for (String val : vals) {
            String v = val.trim();
            if (v.length() > 0)
                strs.add(v);
        }
        return strs;
    }
}

Related

  1. csvLineParse(String line, char delimiter)
  2. csvSplitLine(String line, char fieldSeparator)
  3. parse(final String csvString)
  4. parseCsv(InputStream csvInput)
  5. parseCsv(InputStream fileStream)
  6. parseCSV(String csv)
  7. parseCSV(String csvString)
  8. parseCSV(String data, char... ch)
  9. parseCsvFile(String filename, String csvSplitBy, boolean skipHeader)