Java ListIterator Usage stringToList(String commas)

Here you can find the source of stringToList(String commas)

Description

Splits a string with commas in it into a string List.

License

Open Source License

Parameter

Parameter Description
commas The string to split.

Return

The split string List.

Declaration

public static List<String> stringToList(String commas) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;

public class Main {
    /**//  w w w . j ava2s  .c  o  m
     * Splits a string with commas in it into a string List.
     * 
     * @param commas The string to split.
     * @return The split string List.
     */
    public static List<String> stringToList(String commas) {
        List<String> list = new ArrayList<String>();
        ListIterator<String> iterator = Arrays.asList(commas.split("\\s*,\\s*")).listIterator();

        if (iterator != null) {
            while (iterator.hasNext()) {
                list.add(iterator.next());
            }
        } else
            list = Arrays.asList(commas);

        return list;
    }
}

Related

  1. reset(ListIterator iterator)
  2. retainAll(final List list, final Collection indices)
  3. rewindIterator( @SuppressWarnings("rawtypes") ListIterator it, int n)
  4. sort(List aList)
  5. stringCrossJoin(List> candidates)
  6. stripQuotes(List input)
  7. toArray(List a)
  8. toCFML(Object obj)
  9. toCharArrays(List strings)