Split String To List with default separator - Android java.lang

Android examples for java.lang:String Split

Description

Split String To List with default separator

Demo Code

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

public class Main {

  
  public static List<String> parseStringToList(String srcString, String split) {
    List<String> list = null;
    if (split == null) {
      split = ",";
    }//from w  ww  . j  a v  a2s .co m
    String[] strArr = srcString.split(split);
    if (strArr != null && strArr.length > 0) {
      list = new ArrayList<String>(strArr.length);
      for (String str : strArr) {
        list.add(str);
      }
    }

    return list;
  }

}

Related Tutorials