Java String to List strToAList(String strTokenize)

Here you can find the source of strToAList(String strTokenize)

Description

Takes a string and returns the array list for that string.

License

GNU General Public License

Declaration

public static ArrayList strToAList(String strTokenize) 

Method Source Code

//package com.java2s;
/*//from w ww .j av  a2 s  .c  om
 * Copyright (C) 2015  University of Oregon
 *
 * You may distribute under the terms of either the GNU General Public
 * License or the Apache License, as specified in the LICENSE file.
 *
 * For more information, see the LICENSE file.
 */

import java.util.*;

public class Main {
    /**
     *  Takes a string and returns the array list for that string.
     */
    public static ArrayList strToAList(String strTokenize) {
        return strToAList(strTokenize, true);
    }

    /**
     *  Takes a string and returns the array list for that string.
     *  @strTokenize    string from which an arraylist should be made.
     *  @strDelim       delimeter string for the tokenizer.
     */
    public static ArrayList strToAList(String strTokenize, String strDelim) {
        return strToAList(strTokenize, true, strDelim);
    }

    /**
     *  Takes a string and returns the array list for that string.
     *  @param strTokenize  the string from which an arraylist should be made.
     *  @param bAllowDups   true if duplicates should be allowed in the arraylist.
     */
    public static ArrayList strToAList(String strTokenize,
            boolean bAllowDups) {
        return strToAList(strTokenize, bAllowDups, " \t\n\r\f");
    }

    /**
     *  Takes a string and returns the array list for that string.
     *  @param strTokenize  the string from which an arraylist should be made.
     *  @param bAllowDups   true if duplicates should be allowed in the arraylist.
     *  @param strDelim     delimeter string for the tokenizer.
     */
    public static ArrayList strToAList(String strTokenize,
            boolean bAllowDups, String strDelim) {
        ArrayList<String> aListValues = new ArrayList<String>();
        String strValue;

        if (strTokenize == null)
            return aListValues;

        StringTokenizer strTokTmp = new StringTokenizer(strTokenize,
                strDelim);
        while (strTokTmp.hasMoreTokens()) {
            strValue = strTokTmp.nextToken();
            if (strValue != null && strValue.trim().length() > 0) {
                if (bAllowDups || !aListValues.contains(strValue))
                    aListValues.add(strValue);
            }
        }

        return aListValues;
    }
}

Related

  1. stringToList(String text, String seperator)
  2. stringToList(String toList)
  3. stringToList(String toList, String delimiter)
  4. stringToList(String value)
  5. stringToListOfTags(String p)
  6. strToList(String str, String regex)
  7. strToList(String str, String separator)
  8. strToList(String str, String split)
  9. strToList(String value)