Here you can find the source of toBoolean(final Object value, final boolean defaultValue)
public static final boolean toBoolean(final Object value, final boolean defaultValue)
//package com.java2s; public class Main { public static final boolean toBoolean(final Object value, final boolean defaultValue) { final Boolean v = toBoolean(value); return v == null ? defaultValue : v.booleanValue(); }//from w w w . j a v a2 s . c o m public static final Boolean toBoolean(final Object obj) { if (obj == null) { return null; } else if (obj instanceof Boolean) { return (Boolean) obj; } else if (obj instanceof Number) { return ((Number) obj).intValue() == 0 ? Boolean.FALSE : Boolean.TRUE; } else if (obj instanceof String) { final String s = (String) obj; if (s.equalsIgnoreCase("true")) { return Boolean.TRUE; } else if (s.equalsIgnoreCase("false")) { return Boolean.FALSE; } else { try { return new Boolean(Integer.parseInt((String) obj) != 0); } catch (final Throwable t) { return Boolean.FALSE; } } } return null; } }