Here you can find the source of castToBoolean(Object value)
public static final Boolean castToBoolean(Object value)
//package com.java2s; //License from project: Apache License public class Main { public static final Boolean castToBoolean(Object value) { if (value == null) { return null; }//www.ja v a 2 s.co m if (value instanceof Boolean) { return (Boolean) value; } if (value instanceof Number) { return ((Number) value).intValue() > 0; } if (value instanceof String) { String strVal = (String) value; if (strVal.length() == 0) { return null; } if ("true".equalsIgnoreCase(strVal)) { return Boolean.TRUE; } if ("false".equalsIgnoreCase(strVal)) { return Boolean.FALSE; } if ("1".equals(strVal)) { return Boolean.TRUE; } if ("0".equals(strVal)) { return Boolean.FALSE; } if ("yes".equalsIgnoreCase(strVal)) { return Boolean.TRUE; } if ("no".equalsIgnoreCase(strVal)) { return Boolean.TRUE; } if ("null".equals(strVal) || "NULL".equals(strVal)) { return null; } if (strVal.trim().length() == 0) { return null; } } throw new IllegalArgumentException("can not cast to boolean, value : " + value); } }