Java Boolean From toBoolean(String value, boolean defaultValue)

Here you can find the source of toBoolean(String value, boolean defaultValue)

Description

to Boolean

License

Open Source License

Declaration

public static Boolean toBoolean(String value, boolean defaultValue) 

Method Source Code

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

public class Main {

    public static Boolean toBoolean(String value, boolean defaultValue) {
        if (isEmpty(value))
            return defaultValue;

        try {/*from w ww .j a  v  a2s .co m*/
            return Boolean.parseBoolean(value);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public static Boolean toBoolean(String value) {
        return toBoolean(value, false);
    }

    public static boolean isEmpty(String str) {
        if (str == null)
            return true;

        if ("".equals(str.trim()))
            return true;

        return false;
    }
}

Related

  1. toBoolean(String value)
  2. toBoolean(String value, boolean _default)
  3. toBoolean(String value, boolean dEfault)
  4. toBoolean(String value, boolean defaultValue)
  5. toBoolean(String value, boolean defaultValue)
  6. toBoolean(String value, boolean defaultValue)
  7. toBoolean(StringBuilder value)
  8. toBooleanA(byte[] data)
  9. toBooleanArray(byte a, boolean[] buf)