Java Boolean From toBoolean(String string, boolean defaultValue)

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

Description

to Boolean

License

MIT License

Declaration

public static boolean toBoolean(String string, boolean defaultValue) 

Method Source Code

//package com.java2s;
/*/*from w ww .  ja  v  a  2 s.c o  m*/
 * oxCore is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

public class Main {
    public static boolean toBoolean(String string, boolean defaultValue) {
        if (isEmpty(string)) {
            return defaultValue;
        }

        try {
            return Boolean.parseBoolean(string);
        } catch (NumberFormatException ex) {
            return defaultValue;
        }
    }

    public static boolean isEmpty(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return true;
        }

        for (int i = 0; i < strLen; i++) {
            if (Character.isWhitespace(str.charAt(i)) == false) {
                return false;
            }
        }

        return true;
    }
}

Related

  1. toBoolean(String str)
  2. toBoolean(String str)
  3. toBoolean(String str)
  4. toBoolean(String string)
  5. toBoolean(String string)
  6. toBoolean(String text)
  7. toBoolean(String val)
  8. toBoolean(String value)
  9. toBoolean(String value)