Here you can find the source of convertStringToPrimitive(Object object, Class toType)
public static Object convertStringToPrimitive(Object object, Class toType)
//package com.java2s; /**//from w ww . j a v a 2s. c o m * * Licensed under the GNU General Public License (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.gnu.org/licenses/gpl.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * * @author Vadim Kisen * * copyright 2010 by uTest */ public class Main { public static Object convertStringToPrimitive(Object object, Class toType) { if (toType == boolean.class || toType == Boolean.class) { return Boolean.valueOf((String) object); } if (toType == char.class || toType == Character.class) { return new Character(((String) object).charAt(0)); } if (toType == byte.class || toType == Byte.class) { return new Byte((String) object); } if (toType == short.class || toType == Short.class) { return new Short((String) object); } if (toType == int.class || toType == Integer.class) { return new Integer((String) object); } if (toType == long.class || toType == Long.class) { return new Long((String) object); } if (toType == float.class || toType == Float.class) { return new Float((String) object); } if (toType == double.class || toType == Double.class) { return new Double((String) object); } return null; } }