Java String to List convertToList(String vars)

Here you can find the source of convertToList(String vars)

Description

Converts comma-separated string into a list.

License

MIT License

Parameter

Parameter Description
vars a parameter

Declaration

public static List<String> convertToList(String vars) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *  Copyright ? 2012-2015 eBay Software Foundation
 *  This program is dual licensed under the MIT and Apache 2.0 licenses.
 *  Please see LICENSE for more information.
 *******************************************************************************/

import java.util.ArrayList;
import java.util.List;

public class Main {
    private static final String STRING_LIST_SEPARATOR = ",";

    /**//from  w ww  . j  ava  2 s  . c o m
     * Converts comma-separated string into a list. Performs trimming, ignores empty strings. For EPL like<br>
     * <code> 
     * SELECT com.ebay.jetstream.util.StringUtils.convertToList('One, Two, Three, ') AS TopicList FROM ESPTestEvent1
     * </code><br>
     * it returns a list of three strings: "One", "Two", "Three"
     * 
     * @param vars
     * @return
     */
    public static List<String> convertToList(String vars) {
        List<String> resultList = new ArrayList<String>();
        String[] resultArray = vars.split(STRING_LIST_SEPARATOR);
        for (String var : resultArray) {
            var = var.trim();
            if (var.length() > 0) {
                resultList.add(var);
            }
        }
        return resultList;
    }
}

Related

  1. convertTextToStringList(String tagText)
  2. convertTextToStringList(String text)
  3. convertToList(String inputString)
  4. convertToList(String str)
  5. convertToList(String string, String delim)
  6. convertToList(String[] array)
  7. stringsToList(final String[] src)
  8. stringToArrayList(String idString)
  9. stringToBooleanList(final String str, final boolean[] listData)