Java Array Create toArray(String text)

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

Description

Convert the given text to String array.

License

Open Source License

Parameter

Parameter Description
text The text in format "[a,b,c]"

Return

The String array

Declaration

public static String[] toArray(String text) 

Method Source Code

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

public class Main {
    /**/*  w  ww. j  a v  a2s .com*/
     * Convert the given text to String array.
     * 
     * @param text
     *            The text in format "[a,b,c]"
     * @return The String array
     * 
     * @see #toString(Object[])
     */
    public static String[] toArray(String text) {
        if (text == null)
            return null;

        text = text.trim().replaceAll("\\[(.*)\\]", "$1").trim();

        String regex = " *, *";
        String[] array = text.split(regex);

        return array;
    }
}

Related

  1. toArray(String source, String delimiter)
  2. toArray(String str)
  3. toArray(String str)
  4. toArray(String str, String split)
  5. toArray(String string)
  6. toArray(T... items)
  7. toArray(T... items)
  8. toArrayClass(String className)
  9. toArrayDouble(final int[] array)