Java String Split splitToList(final String listString, final String split)

Here you can find the source of splitToList(final String listString, final String split)

Description

split To List

License

Apache License

Declaration

public static List<String> splitToList(final String listString, final String split) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import java.util.List;

public class Main {

    public static List<String> splitToList(final String listString, final String split) {
        return splitToList(listString, split, false);
    }//from w  ww.j  a va  2 s.  c o m

    public static List<String> splitToList(final String listString, final String split, boolean ignoreNullString) {
        if (listString == null) {
            return new ArrayList<String>(0);
        }
        if (split == null || split.length() == 0) {
            return new ArrayList<String>(0);
        }
        List<String> result = new ArrayList<String>();

        String tmpListString = listString.trim();

        String[] array = tmpListString.split(split);
        for (String str : array) {
            str = str.trim();
            if (!"".equals(str)) {
                if (ignoreNullString && "NULL".equals(str)) {
                    continue;
                }
                result.add(str);
            }
        }
        return result;
    }
}

Related

  1. splitTerms(String queryString)
  2. splitText(String text)
  3. splitToInteger(String str)
  4. splitTokens(final String targets)
  5. splitTokens(String text)
  6. splitToList(String s)
  7. splitToList(String valueString)
  8. splitToTopLevelJsonObjects(String s)
  9. splitTypeArguments(final String nestedTypes)