Java Java String Format toJavaTypes(Class clazz, String value)

Here you can find the source of toJavaTypes(Class clazz, String value)

Description

to Java Types

License

Apache License

Declaration

public static Object toJavaTypes(Class<?> clazz, String value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static Object toJavaTypes(Class<?> clazz, String value) {
        if (Boolean.class == clazz || boolean.class == clazz)
            return Boolean.parseBoolean(value);
        if (Byte.class == clazz || byte.class == clazz)
            return Byte.parseByte(value);
        if (Short.class == clazz || short.class == clazz)
            return Short.parseShort(value);
        if (Integer.class == clazz || int.class == clazz)
            return Integer.parseInt(value);
        if (Long.class == clazz || long.class == clazz)
            return Long.parseLong(value);
        if (Float.class == clazz || float.class == clazz)
            return Float.parseFloat(value);
        if (Double.class == clazz || double.class == clazz)
            return Double.parseDouble(value);
        if ((Character.class == clazz || char.class == clazz) && value.length() == 1)
            return value.charAt(0);
        return value;
    }//from   w  ww  . j a v  a 2s . c o m
}

Related

  1. toJavaString(String buf)
  2. toJavaString(String text)
  3. toJavaTime(double time)
  4. toJavaTypeIdentifier(String string)
  5. toJavaTypeName(String edmTypeName)
  6. toJavaVariable(Class compClass, String name)