Java String to List StringToList(String listText, String regex)

Here you can find the source of StringToList(String listText, String regex)

Description

String To List

License

Open Source License

Declaration

public static List<String> StringToList(String listText, String regex) 

Method Source Code


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

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

public class Main {
    public static List<String> StringToList(String listText, String regex) {

        if (listText == null || listText.equals("")) {
            return null;
        }/*from w  w w . ja va  2s .  c  om*/
        List<String> list = new ArrayList<String>();
        if (listText.contains(regex)) {
            String[] text = listText.split(regex);
            for (String str : text) {
                list.add(str.replaceAll("\\s*", ""));
            }

        } else {
            list.add(listText.replaceAll("\\s*", ""));
        }
        return list;
    }
}

Related

  1. stringToList(String delimitedString)
  2. stringToList(String input)
  3. stringToList(String keywords, String delimiter)
  4. stringToList(String listString, String delimiter)
  5. stringToList(String listText)
  6. stringToList(String s)
  7. stringToList(String s)
  8. stringToList(String s)
  9. stringToList(String source)