Java String Split splitToList(String valueString)

Here you can find the source of splitToList(String valueString)

Description

split To List

License

Open Source License

Declaration

public static List<String> splitToList(String valueString) 

Method Source Code

//package com.java2s;
/*************************************************************************************
 * Copyright (c) 2014 Red Hat, Inc. and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * //from   w  ww .j a  v a  2 s.  c  o  m
 * Contributors:
 *     JBoss by Red Hat - Initial implementation.
 ************************************************************************************/

import java.util.ArrayList;
import java.util.Collection;

import java.util.List;

public class Main {
    public static List<String> splitToList(String valueString) {
        if (valueString == null) {
            return null;
        }
        ArrayList<String> result = new ArrayList<>();
        splitToCollection(result, valueString);
        return result;
    }

    private static void splitToCollection(Collection<String> collection, String valueString) {
        String[] splitValues = valueString.split(",");//$NON-NLS-1$
        for (String value : splitValues) {
            value = value.trim();
            if (!value.isEmpty()) {
                collection.add(value);
            }
        }
    }
}

Related

  1. splitToInteger(String str)
  2. splitTokens(final String targets)
  3. splitTokens(String text)
  4. splitToList(final String listString, final String split)
  5. splitToList(String s)
  6. splitToTopLevelJsonObjects(String s)
  7. splitTypeArguments(final String nestedTypes)
  8. splitTypes(String fullName)
  9. splitValues(String strValues)