Here you can find the source of toBoolean(final String value)
Parameter | Description |
---|---|
value | the value |
public static boolean toBoolean(final String value)
//package com.java2s; //License from project: Open Source License public class Main { /** The Constant DEFAULT_VALUE. */ public static final boolean DEFAULT_VALUE = false; /**/* w ww. j a v a 2 s . co m*/ * To boolean. * * @param value * the value * @return true, if successful */ public static boolean toBoolean(final String value) { return toBoolean(value, DEFAULT_VALUE); } /** * To boolean. * * @param value * the value * @param defaultValue * the default value * @return true, if successful */ public static boolean toBoolean(final String value, final boolean defaultValue) { if (value == null || value.length() == 0) { return defaultValue; } else { if ("true".equalsIgnoreCase(value)) { return true; } if ("on".equalsIgnoreCase(value)) { return true; } if ("yes".equalsIgnoreCase(value)) { return true; } // if ("false".equalsIgnoreCase(value)) { return false; } if ("off".equalsIgnoreCase(value)) { return false; } if ("no".equalsIgnoreCase(value)) { return false; } // switch (value.charAt(0)) { case '1': case 't': case 'T': case 'y': case 'Y': return true; case '0': case 'f': case 'F': case 'n': case 'N': return false; default: return defaultValue; } } } }