Here you can find the source of fromString(String string, Class
public static <T> T fromString(String string, Class<T> arrayClass)
//package com.java2s; //License from project: Apache License public class Main { public static <T> T fromString(String string, Class<T> arrayClass) { String stringArray = string.replaceAll("[\\[\\]]", ""); String[] tokens = stringArray.split(","); int length = tokens.length; if (boolean[].class.equals(arrayClass)) { boolean[] array = new boolean[length]; for (int i = 0; i < tokens.length; i++) { array[i] = Boolean.valueOf(tokens[i]); }/*from w ww. jav a 2s. c o m*/ return (T) array; } else if (byte[].class.equals(arrayClass)) { byte[] array = new byte[length]; for (int i = 0; i < tokens.length; i++) { array[i] = Byte.valueOf(tokens[i]); } return (T) array; } else if (short[].class.equals(arrayClass)) { short[] array = new short[length]; for (int i = 0; i < tokens.length; i++) { array[i] = Short.valueOf(tokens[i]); } return (T) array; } else if (int[].class.equals(arrayClass)) { int[] array = new int[length]; for (int i = 0; i < tokens.length; i++) { array[i] = Integer.valueOf(tokens[i]); } return (T) array; } else if (long[].class.equals(arrayClass)) { long[] array = new long[length]; for (int i = 0; i < tokens.length; i++) { array[i] = Long.valueOf(tokens[i]); } return (T) array; } else if (float[].class.equals(arrayClass)) { float[] array = new float[length]; for (int i = 0; i < tokens.length; i++) { array[i] = Float.valueOf(tokens[i]); } return (T) array; } else if (double[].class.equals(arrayClass)) { double[] array = new double[length]; for (int i = 0; i < tokens.length; i++) { array[i] = Double.valueOf(tokens[i]); } return (T) array; } else if (char[].class.equals(arrayClass)) { char[] array = new char[length]; for (int i = 0; i < tokens.length; i++) { array[i] = tokens[i].length() > 0 ? tokens[i].charAt(0) : Character.MIN_VALUE; } return (T) array; } else { return (T) tokens; } } }