Java Boolean From toBoolean(Object obj)

Here you can find the source of toBoolean(Object obj)

Description

to Boolean

License

Apache License

Declaration

public static Boolean toBoolean(Object obj) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    private static final Object NULL = null;

    public static Boolean toBoolean(Object obj) {
        if (isNull(obj)) {
            return getNull();
        }/*  ww w  .  j  a va 2s.c om*/
        if (obj instanceof Boolean) {
            return (Boolean) obj;
        }
        if ("true".equalsIgnoreCase(obj.toString())) {
            return Boolean.TRUE;
        }
        if ("false".equalsIgnoreCase(obj.toString())) {
            return Boolean.FALSE;
        }
        return getNull();
    }

    public static boolean isNull(Object obj) {
        return obj == NULL;
    }

    @SuppressWarnings("unchecked")
    public static <T> T getNull() {
        return (T) NULL;
    }
}

Related

  1. toBoolean(Object obj)
  2. toBoolean(Object obj)
  3. toBoolean(Object obj)
  4. toBoolean(Object obj)
  5. toBoolean(Object obj)
  6. toBoolean(Object obj)
  7. toBoolean(Object obj)
  8. toBoolean(Object obj)
  9. toBoolean(Object object)