Java String to List toList(String val, String separator)

Here you can find the source of toList(String val, String separator)

Description

to List

License

Open Source License

Declaration

public static List<String> toList(String val, String separator) 

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> toList(String val, String separator) {
        List<String> list = new ArrayList<String>();
        if (!isEmpty(val) && val.indexOf(separator) > -1) {
            String[] arr = val.split(separator);
            for (String item : arr) {
                if (!isEmpty(item)) {
                    list.add(item);/*from w w  w.java  2 s.co m*/
                }
            }
        }
        return list;
    }

    public static boolean isEmpty(String val) {
        return val == null || val.trim().length() == 0;
    }
}

Related

  1. toList(String str)
  2. toList(String string)
  3. toList(String text)
  4. toList(String transaction)
  5. toList(String val)