Java Collection Create stringToCollection(String string)

Here you can find the source of stringToCollection(String string)

Description

Returns a comma-delimitted list of Strings as a Collection.

License

Open Source License

Return

a Collection representing the String.

Declaration

public static Collection<String> stringToCollection(String string) 

Method Source Code

//package com.java2s;
/**/*from w  w w  .j a v  a2s .  c o  m*/
 * <p>
 * Simple utility class for String operations useful across the framework.
 * <p/>
 * <p>
 * Some methods in this class were copied from the Spring Framework so we didn't
 * have to re-invent the wheel, and in these cases, we have retained all
 * license, copyright and author information.
 *
 * @since 0.9
 */

import java.util.*;

public class Main {
    /**
     * Returns a comma-delimitted list of Strings as a Collection.
     *
     * @return a Collection representing the String.
     */
    public static Collection<String> stringToCollection(String string) {
        if (string == null || string.trim().length() == 0) {
            return Collections.emptyList();
        }
        Collection<String> collection = new ArrayList<String>();
        StringTokenizer tokens = new StringTokenizer(string, ",");
        while (tokens.hasMoreTokens()) {
            collection.add(tokens.nextToken().trim());
        }
        return collection;
    }
}

Related

  1. createStringCollection(Class clazz, String... elements)
  2. createStringFromCollection(Collection svcInterfaces)
  3. createTextFromList(Collection list)
  4. createUniqueName(String baseName, Collection names)
  5. stringToCollection(String string)
  6. stringToCollection(String string, String delim)
  7. toCollection(C c, E... elements)
  8. toCollection(Class cls, Iterable iterable)
  9. toCollection(Class cls, T[] array)