Here you can find the source of toBoolean(String value)
Parameter | Description |
---|---|
value | a value string |
Parameter | Description |
---|---|
IllegalArgumentException | if format error has occured |
static Boolean toBoolean(String value) throws IllegalArgumentException
//package com.java2s; //License from project: BSD License public class Main { /**// w ww . j av a 2 s.co m * Converts the specified value string to the Boolean value. * If the specified string is null, blank or 'false', this method returns false. * If it is "true", this method returns true. These comparation is case insensitive. * Otherwise, this method returns null. * * @param value a value string * @return a {@code Boolean} object * @throws IllegalArgumentException if format error has occured */ static Boolean toBoolean(String value) throws IllegalArgumentException { if (value == null || value.equals("")) { //the option not specified or a blank value specified return false; } if (value.equalsIgnoreCase("true")) { return true; } if (value.equalsIgnoreCase("false")) { return false; } throw new IllegalArgumentException("invalid boolean value : " + value); } }