Java Boolean Parse tryParseBool(Object obj, Boolean defaultVal)

Here you can find the source of tryParseBool(Object obj, Boolean defaultVal)

Description

try Parse Bool

License

Apache License

Declaration

public static Boolean tryParseBool(Object obj, Boolean defaultVal) 

Method Source Code

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

public class Main {
    public static Boolean tryParseBool(Object obj, Boolean defaultVal) {
        if (obj == null)
            return defaultVal;
        if (obj instanceof Boolean)
            return (Boolean) obj;
        try {//  w  w w.j  a v  a 2 s  . co m
            String val = obj.toString();
            return Boolean.parseBoolean(val);
        } catch (Exception e) {
            return defaultVal;
        }
    }
}

Related

  1. tryParseBool(String value)
  2. tryParseBoolean(String value)
  3. tryParseBoolean(String value)