Commons Lang、BooleanUtils.toBoolean()
import org.apache.commons.lang.BooleanUtils; public class C2009032300 { public static void main(String[] args) { System.out.println(BooleanUtils.toBoolean(true)); System.out.println(BooleanUtils.toBoolean((Boolean)null)); System.out.println(BooleanUtils.toBoolean(1)); System.out.println(BooleanUtils.toBoolean(0)); System.out.println(BooleanUtils.toBoolean(new Integer(1), new Integer(1), new Integer(2))); //System.out.println(BooleanUtils.toBoolean(new Integer(0), new Integer(1), new Integer(2))); System.out.println(BooleanUtils.toBoolean(1, 1, 2)); System.out.println(BooleanUtils.toBoolean("true")); System.out.println(BooleanUtils.toBoolean("on")); System.out.println(BooleanUtils.toBoolean("yes")); System.out.println(BooleanUtils.toBoolean("foo")); System.out.println(BooleanUtils.toBoolean("TRUE", "TRUE", "FALSE")); } }
で、
true false true false true true true true true false true
「toBoolean(Integer value, Integer trueValue, Integer falseValue)」や「toBoolean(String str, String trueString, String falseString)」は、true や flase の条件のときに返す値を指定するのではなく、true や false を判定する比較する値のことだった。どちらにも一致しない場合は例外が発生