Here you can find the source of parseCSVIntegers(String csv)
Parameter | Description |
---|---|
csv | the string |
Parameter | Description |
---|---|
NumberFormatException | if one of the numbers is invalid |
public static List<Integer> parseCSVIntegers(String csv)
//package com.java2s; /**//from w w w . j a va 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 integers * @param csv the string * @return the list of integers * @throws NumberFormatException if one of the numbers is invalid */ public static List<Integer> parseCSVIntegers(String csv) { String[] vals = csv.split(","); List<Integer> ints = new ArrayList<Integer>(); for (String val : vals) { String v = val.trim(); if (v.length() > 0) { Integer n = Integer.parseInt(v); if (n != null) ints.add(n); } } return ints; } }