Java Comma Separated List toListOfNonEmptyStringsDelimitedByCommaOrSemicolon(String s)

Here you can find the source of toListOfNonEmptyStringsDelimitedByCommaOrSemicolon(String s)

Description

to List Of Non Empty Strings Delimited By Comma Or Semicolon

License

Open Source License

Declaration

public static List toListOfNonEmptyStringsDelimitedByCommaOrSemicolon(String s) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    /**//ww w  .j  av  a2s  .c  o  m
     * Define split characters *
     */
    private final static String SEPARATOR = "[,;]";

    public static List toListOfNonEmptyStringsDelimitedByCommaOrSemicolon(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++) {
            String term = terms[i].trim();
            if (term.length() > 0) {
                results.add(term);
            }
        }

        return results;
    }
}

Related

  1. toCommaSeparated(List list)
  2. toCommaSeparated(List list)
  3. toCommaSeparatedString(List list)
  4. toList(final String commaSeparatedString)
  5. toListDelimitedByComma(String s)
  6. toListOfStringsDelimitedByCommaOrSemicolon(String s)