Returns a String array of the the CSV value specified with the specified delimiter. - Java File Path IO

Java examples for File Path IO:CSV File

Description

Returns a String array of the the CSV value specified with the specified delimiter.

Demo Code

/*// w w w.  j a  v  a  2s  .  c  o m
 * MiscUtils.java
 *
 * Copyright (C) 2002-2013 Takis Diakoumis
 *
 * This program 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 any later version.
 *
 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
//package com.java2s;

import java.util.ArrayList;

import java.util.List;

import java.util.StringTokenizer;

public class Main {
    /**
     * Returns a <code>String</code> array of the the CSV value
     * specified with the specfied delimiter.
     *
     * @param csvString the CSV value
     * @param delim the delimiter used in the CSV value
     * @return an array of split values
     */
    public static String[] splitSeparatedValues(String csvString,
            String delim) {
        StringTokenizer st = new StringTokenizer(csvString, delim);
        List<String> list = new ArrayList<String>(st.countTokens());

        while (st.hasMoreTokens()) {
            list.add(st.nextToken());
        }

        String[] values = (String[]) list.toArray(new String[list.size()]);
        return values;
    }
}

Related Tutorials