Java Boolean From toBoolean(Object val, boolean defValue)

Here you can find the source of toBoolean(Object val, boolean defValue)

Description

to Boolean

License

LGPL

Declaration

public static boolean toBoolean(Object val, boolean defValue) 

Method Source Code

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

public class Main {
    public static boolean toBoolean(Object val, boolean defValue) {
        if (val != null) {
            String value = String.valueOf(val);
            try {
                return Boolean.valueOf(value) || toInt(val, 0) == 1;
            } catch (Exception e) {
            }/*w  w  w.ja v  a 2 s  .com*/
        }
        return defValue;
    }

    public static int toInt(Object num, int defValue) {
        if (num != null) {
            String value = String.valueOf(num);
            try {
                return Integer.parseInt(value);
            } catch (Exception e) {
            }
        }
        return defValue;
    }
}

Related

  1. toBoolean(Object object, Boolean defaultValue)
  2. toBoolean(Object property, boolean defaultValue)
  3. toBoolean(Object s)
  4. toBoolean(Object v)
  5. toBoolean(Object val)
  6. toBoolean(Object value)
  7. toBoolean(Object value)
  8. toBoolean(Object value)
  9. toBoolean(Object value)