Here you can find the source of toListOfStringsDelimitedByCommaOrSemicolon(String s)
Parameter | Description |
---|---|
s | input string delimited by comma or semicolon |
public static List toListOfStringsDelimitedByCommaOrSemicolon(String s)
//package com.java2s; import java.util.*; public class Main { /**// w w w . j av a2 s . co m * Define split characters * */ private final static String SEPARATOR = "[,;]"; /** * This version returns the complete list, including empty string, if such entry is empty * * @param s input string delimited by comma or semicolon * @return list of strings where deliminators are stripped off. if no content * is found between 2 delimitors then empty string is returned in its place */ public static List toListOfStringsDelimitedByCommaOrSemicolon(String s) { if (s == null) { return Collections.EMPTY_LIST; } List results = new ArrayList(); String[] terms = s.split(SEPARATOR); for (int i = 0; i < terms.length; i++) { //this has empty string if nothing is found String term = terms[i].trim(); results.add(term); } return results; } }