Java Array From toArray(String array)

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

Description

Cast a string to an array of objects

String should have the format "[a,b,c]".

License

Open Source License

Parameter

Parameter Description
array the string to be parsed

Return

the parsed array

Declaration

public static String[] toArray(String array) 

Method Source Code

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

public class Main {
    /**//from  w  ww  .  ja  va 2 s.c  om
     * Cast a string to an array of objects
     * <p>
     * String should have the format <code>"[a,b,c]"</code>.
     * 
     * @param array
     *            the string to be parsed
     * @return the parsed array
     */
    public static String[] toArray(String array) {
        // Empty array []
        if (array.length() == 2)
            return new String[0];

        return array.substring(1, array.length() - 1).split(",");
    }
}

Related

  1. toArray(Object a)
  2. toArray(Object foo)
  3. toArray(Object o)
  4. toArray(Object... args)
  5. toArray(Object... values)
  6. toArray(String emails)
  7. toArray(String number)
  8. toArray(String s)
  9. toArray(String s)