Java Boolean From toBoolean(String value, boolean dEfault)

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

Description

If value is "true", then true is returned.

License

Open Source License

Declaration

public static boolean toBoolean(String value, boolean dEfault) 

Method Source Code

//package com.java2s;
/**//from  w  ww  .  j  a va2 s  .c om
 * Logback: the reliable, generic, fast and flexible logging framework.
 * Copyright (C) 1999-2013, QOS.ch. All rights reserved.
 *
 * This program and the accompanying materials are dual-licensed under
 * either the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation
 *
 *   or (per the licensee's choosing)
 *
 * under the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation.
 */

public class Main {
    /**
     * If <code>value</code> is "true", then <code>true</code> is returned. If
     * <code>value</code> is "false", then <code>true</code> is returned.
     * Otherwise, <code>default</code> is returned.
     * <p/>
     * <p> Case of value is unimportant.
     */
    public static boolean toBoolean(String value, boolean dEfault) {
        if (value == null) {
            return dEfault;
        }

        String trimmedVal = value.trim();

        if ("true".equalsIgnoreCase(trimmedVal)) {
            return true;
        }

        if ("false".equalsIgnoreCase(trimmedVal)) {
            return false;
        }

        return dEfault;
    }
}

Related

  1. toBoolean(String value)
  2. toBoolean(String value)
  3. toBoolean(String value)
  4. toBoolean(String value)
  5. toBoolean(String value, boolean _default)
  6. toBoolean(String value, boolean defaultValue)
  7. toBoolean(String value, boolean defaultValue)
  8. toBoolean(String value, boolean defaultValue)
  9. toBoolean(String value, boolean defaultValue)