Commons Lang、BooleanUtils.toBooleanObject()
import org.apache.commons.lang.BooleanUtils; public class C2009032500 { public static void main(String[] args) { System.out.println(BooleanUtils.toBooleanObject(true)); System.out.println(BooleanUtils.toBooleanObject(false)); System.out.println("***"); System.out.println(BooleanUtils.toBooleanObject(new Integer(2))); System.out.println(BooleanUtils.toBooleanObject(new Integer(1))); System.out.println(BooleanUtils.toBooleanObject(new Integer(0))); System.out.println(BooleanUtils.toBooleanObject(new Integer(10), new Integer(10), new Integer(20), new Integer(30))); System.out.println(BooleanUtils.toBooleanObject(new Integer(20), new Integer(10), new Integer(20), new Integer(30))); System.out.println(BooleanUtils.toBooleanObject(new Integer(30), new Integer(10), new Integer(20), new Integer(30))); System.out.println("***"); System.out.println(BooleanUtils.toBooleanObject(2)); System.out.println(BooleanUtils.toBooleanObject(1)); System.out.println(BooleanUtils.toBooleanObject(0)); System.out.println(BooleanUtils.toBooleanObject(10, 10, 20, 30)); System.out.println(BooleanUtils.toBooleanObject(20, 10, 20, 30)); System.out.println(BooleanUtils.toBooleanObject(30, 10, 20, 30)); System.out.println("***"); System.out.println(BooleanUtils.toBooleanObject("true")); System.out.println(BooleanUtils.toBooleanObject("on")); System.out.println(BooleanUtils.toBooleanObject("yes")); System.out.println(BooleanUtils.toBooleanObject("false")); System.out.println(BooleanUtils.toBooleanObject("off")); System.out.println(BooleanUtils.toBooleanObject("no")); System.out.println(BooleanUtils.toBooleanObject("TRUE")); System.out.println(BooleanUtils.toBooleanObject("foo")); System.out.println(BooleanUtils.toBooleanObject("10", "10", "20", "30")); System.out.println(BooleanUtils.toBooleanObject("20", "10", "20", "30")); System.out.println(BooleanUtils.toBooleanObject("30", "10", "20", "30")); } }
で、
true false *** true true false true false null *** true true false true false null *** true true true false false false true null true false null