Java Object to Boolean castBoolean(Object obj)

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

Description

cast Boolean

License

Apache License

Declaration

public static boolean castBoolean(Object obj) 

Method Source Code

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

public class Main {

    public static boolean castBoolean(Object obj, boolean defaultValue) {
        boolean booleanValue = defaultValue;
        if (obj != null) {
            booleanValue = Boolean.parseBoolean(castString(obj));
        }/*from www . ja  va2s.  c  o  m*/
        return booleanValue;
    }

    public static boolean castBoolean(Object obj) {
        return castBoolean(obj, false);
    }

    public static String castString(Object obj, String defaultValue) {
        return obj != null ? String.valueOf(obj) : defaultValue;
    }

    public static String castString(Object obj) {
        return castString(obj, "");
    }
}

Related

  1. asBoolean(Object value)
  2. castBoolean(Object inObject)
  3. castBoolean(Object o)
  4. castBoolean(Object o)
  5. castBoolean(Object o, boolean defaultValue)
  6. castToBoolean(Object value)
  7. castToBoolean(Object value)
  8. castToBoolean(String fieldValue)
  9. objectToBoolean(Object o)