Java String to List stringToList(String str, char delimiter)

Here you can find the source of stringToList(String str, char delimiter)

Description

creates a List from a String "List"

License

LGPL

Parameter

Parameter Description
str String to creates List from
delimiter delimiter to split string

Return

List

Declaration

public static List stringToList(String str, char delimiter) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

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

public class Main {
    /**//from   w  ww .  ja v a  2s .c om
     * creates a List from a String "List"
     * @param str String to creates List from
     * @param delimiter delimiter to split string
     * @return List 
     */
    public static List stringToList(String str, char delimiter) {
        ArrayList list = new ArrayList();
        int len = str.length();
        if (len == 0)
            return list;
        StringBuffer el = new StringBuffer();

        for (int i = 0; i < len; i++) {
            char c = str.charAt(i);
            if (c == delimiter) {
                list.add(el.toString());
                if (el.length() > 0)
                    el = new StringBuffer();
            } else {
                el.append(c);
            }
        }
        list.add(el.toString());
        return list;
    }
}

Related

  1. stringToList(String s)
  2. stringToList(String source)
  3. stringToList(String sText)
  4. stringToList(String str)
  5. stringToList(String str)
  6. stringToList(String str, String delim)
  7. stringToList(String string, String separator)
  8. stringToList(String text, String seperator)
  9. stringToList(String toList)