Here you can find the source of toBoolean(Object o)
public static Boolean toBoolean(Object o)
//package com.java2s; //License from project: LGPL public class Main { public static Boolean toBoolean(Object o) { if (o == null) return null; if (o.getClass() == Boolean.class) return (Boolean) o; if (o.getClass() == Byte.class) return byteToBoolean(((Byte) o)); if (o.getClass() == Character.class) return charToBoolean(((Character) o)); if (o.getClass() == Short.class) return shortToBoolean(((Short) o)); if (o.getClass() == Integer.class) return intToBoolean(((Integer) o)); if (o.getClass() == Long.class) return longToBoolean(((Long) o)); if (o.getClass() == Float.class) return floatToBoolean(((Float) o)); if (o.getClass() == Double.class) return doubleToBoolean(((Double) o)); if (o.getClass() == String.class) return stringToBoolean(((String) o)); return null; }// w w w . ja v a2 s .c o m public static boolean toBoolean(Object o, boolean defaultValue) { if (o == null) return defaultValue; if (o.getClass() == Boolean.class) return (Boolean) o; if (o.getClass() == Byte.class) return byteToBoolean(((Byte) o)); if (o.getClass() == Character.class) return charToBoolean(((Character) o)); if (o.getClass() == Short.class) return shortToBoolean(((Short) o)); if (o.getClass() == Integer.class) return intToBoolean(((Integer) o)); if (o.getClass() == Long.class) return longToBoolean(((Long) o)); if (o.getClass() == Float.class) return floatToBoolean(((Float) o)); if (o.getClass() == Double.class) return doubleToBoolean(((Double) o)); if (o.getClass() == String.class) return stringToBoolean(((String) o), defaultValue); return defaultValue; } public static boolean byteToBoolean(byte b) { return b != 0 ? true : false; } public static boolean charToBoolean(char c) { return c != 0 ? true : false; } public static boolean shortToBoolean(short h) { return h != 0 ? true : false; } public static boolean intToBoolean(int i) { return i != 0 ? true : false; } public static boolean longToBoolean(long l) { return l != 0 ? true : false; } public static boolean floatToBoolean(float f) { return f != 0 ? true : false; } public static boolean doubleToBoolean(double d) { return d != 0 ? true : false; } public static Boolean stringToBoolean(String s) { if (s == null) return null; try { return Boolean.valueOf(s); } catch (NumberFormatException e) { return null; } } public static boolean stringToBoolean(String s, boolean defaultValue) { if (s == null) return defaultValue; try { return Boolean.valueOf(s); } catch (NumberFormatException e) { return defaultValue; } } }