Java Array Create toArray(String str)

Here you can find the source of toArray(String str)

Description

to Array

License

Open Source License

Declaration

public static String[] toArray(String str) 

Method Source Code

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

public class Main {
    public final static String LIST_SEPARATOR = ",|:|;";

    public static String[] toArray(String str) {
        return str.equals("") ? new String[0] : str.split(LIST_SEPARATOR);
    }//from w  ww . j a  va  2  s. c o m

    public static String[] split(String s, String sep, boolean trimWhiteSpace, boolean noEmptyString, int limit) {
        if (trimWhiteSpace == false && noEmptyString == false) {
            return s.split(sep, limit);
        } else if (trimWhiteSpace == false && noEmptyString == true) {
            String[] sArr = s.split("^(\\Q" + sep + "\\E)+");
            if (sArr.length == 1 && sArr[0].length() == 0)
                return (new String[0]);
            else {
                return (sArr[sArr.length - 1].split("(\\Q" + sep + "\\E)+", limit));
            }
        } else if (trimWhiteSpace == true && noEmptyString == false) {
            return (s.split("\\s*\\Q" + sep + "\\E\\s*", limit));
        } else {
            String[] sArr = s.split("^(\\s*\\Q" + sep + "\\E\\s*)+");
            if (sArr.length == 1 && sArr[0].length() == 0)
                return (new String[0]);
            else
                return (sArr[sArr.length - 1].split("(\\s*\\Q" + sep + "\\E\\s*)+", limit));
        }

    }
}

Related

  1. newArray(int length, double start, double increment)
  2. newArray(Object obj, int size)
  3. newArray(Object src, int len)
  4. newArray(String... args)
  5. toArray(String source, String delimiter)
  6. toArray(String str)
  7. toArray(String str, String split)
  8. toArray(String string)
  9. toArray(String text)