Java Boolean From toBoolean(Object obj)

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

Description

to Boolean

License

Open Source License

Declaration

public static boolean toBoolean(Object obj) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static boolean toBoolean(Object obj) {

        return toBoolean(obj, false);
    }/*from  w  w w  .j av  a  2 s.  co  m*/

    public static boolean toBoolean(Object obj, boolean defaultValue) {
        if (obj == null) {
            return defaultValue;
        }
        try {
            return Boolean.parseBoolean(toString(obj));
        } catch (Exception e) {
        }
        return defaultValue;
    }

    public static String toString(Object value) {
        if (value == null) {
            return "";
        }
        return value.toString().trim();
    }
}

Related

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