Java Boolean From toBoolean(String value, boolean defaultValue)

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

Description

to Boolean

License

Apache License

Declaration

public static boolean toBoolean(String value, boolean defaultValue) 

Method Source Code

//package com.java2s;
/*/* w  ww.j  ava 2s . com*/
 * Copyright 2002-2005 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {

    public static boolean toBoolean(String value, boolean defaultValue) {

        if (!defaultValue) {
            if (value == null)
                return defaultValue;
            else if (value.equalsIgnoreCase("true"))
                return true;
            else if (value.equalsIgnoreCase("yes"))
                return true;
            else if (value.equalsIgnoreCase("on"))
                return true;
            else
                return value.equalsIgnoreCase("y");
        } else {
            if (value == null)
                return defaultValue;
            else if (value.equalsIgnoreCase("false"))
                return false;
            else if (value.equalsIgnoreCase("no"))
                return false;
            else if (value.equalsIgnoreCase("off"))
                return false;
            else
                return !value.equalsIgnoreCase("n");
        }
    }
}

Related

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