public static boolean parseBoolean ( String value , boolean defaultValue ) { if ( value == null ) return defaultValue ; value = value . trim ( ) ; // any of the following will final String [ ] acceptedTrue = new String [ ] { "yes" , "true" , "t" , "y" , "1" } ; final String [ ] acceptedFalse = new String [ ] { "no" , "false" , "f" , "n" , "0" } ; for ( String possible : acceptedTrue ) { if ( possible . equalsIgnoreCase ( value ) ) return true ; } for ( String possible : acceptedFalse ) { if ( possible . equalsIgnoreCase ( value ) ) return false ; } throw new IllegalArgumentException ( "Unrecognized boolean value '" + value + "'" ) ; }
Convert a string to a boolean .