Java String to Boolean convertStringToBoolean(String string)

Here you can find the source of convertStringToBoolean(String string)

Description

Convert a string into an appropriate boolean value, true or false.

License

Open Source License

Parameter

Parameter Description
string the input truth value representation

Return

true if the string contains one of the representations of "true", otherwise false

Declaration

public static final Boolean convertStringToBoolean(String string) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  w w w .  j a  va  2 s . c o m*/
     * Convert a string into an appropriate boolean value, true or false. The
     * method converts 1, T, Y, and true (case insensitive) to "true" and anything
     * else to "false".
     * 
     * @param string the input truth value representation
     * @return true if the string contains one of the representations of "true",
     *         otherwise false
     */
    public static final Boolean convertStringToBoolean(String string) {
        Boolean bValue = null;

        if (string != null) {
            if ("1".equals(string) || "T".equalsIgnoreCase(string) || "Y".equalsIgnoreCase(string)
                    || "true".equalsIgnoreCase(string) || "yes".equalsIgnoreCase(string)) {
                bValue = Boolean.TRUE;
            } else {
                bValue = Boolean.FALSE;
            }
        }

        return bValue;
    }
}

Related

  1. atob(String s)
  2. atob(String s)
  3. convertStringToBoolean(String pValue)
  4. convertStringToBoolean(String strBoolean)
  5. convertStringToBoolean(String string)
  6. stringToBoolean(String expr)
  7. stringToBooleanArray(String string, String delim)