Java Boolean From toBoolean(String value)

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

Description

to Boolean

License

Open Source License

Declaration

public static boolean toBoolean(String value) 

Method Source Code

//package com.java2s;
/**/*from  w ww  .j a v  a 2 s  . c  om*/
 *  
 * Copyright (c) 2015 Fannie Mae, All rights reserved.
 * This program and the accompany materials are made available under
 * the terms of the Fannie Mae Open Source Licensing Project available 
 * at https://github.com/FannieMaeOpenSource/ezPie/wiki/License
 * 
 * ezPIE? is a registered trademark of Fannie Mae
 * 
 */

public class Main {
    public static boolean toBoolean(String value) {
        return toBoolean(value, false);
    }

    public static boolean toBoolean(String value, Boolean defaultValue) {
        if (isNullOrEmpty(value))
            return defaultValue;
        else if ("|true|t|y|1|on|yes|".indexOf("|" + value.trim().toLowerCase() + "|") > -1)
            return true;
        else if ("|false|f|n|0|off|no|".indexOf("|" + value.trim().toLowerCase() + "|") > -1)
            return false;
        return defaultValue;
    }

    public static boolean isNullOrEmpty(String value) {
        return (value == null) || value.isEmpty();
    }
}

Related

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