All Downloads are FREE. Search and download functionalities are using the official Maven repository.

framework.utils.ConvertUtil Maven / Gradle / Ivy

There is a newer version: 1.8.2
Show newest version
package framework.utils;

public class ConvertUtil {

    public static int toInteger(Object obj) {
        String str = obj == null ? "0" : obj.toString();
        int i = Integer.parseInt(str);
        return i;
    }

    public static long toLong(Object obj) {
        String str = obj == null ? "0" : obj.toString();
        long l = Long.parseLong(str);
        return l;
    }

    public static String toString(Object obj) {
        if (obj == null) return null;
        String s = obj.toString();
        return s;
    }

    public static boolean toBoolean(Object obj) {
        String str = obj == null ? "false" : obj.toString();
        boolean b = Boolean.parseBoolean(str);
        return b;
    }

    public static void main(String[] arg) {
        System.out.println(toInteger(null));
        System.out.println(toInteger("123"));
        System.out.println(toString(456.2));
        System.out.println(toBoolean("true"));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy