Java String to Boolean asBoolean(String str)

Here you can find the source of asBoolean(String str)

Description

as Boolean

License

Open Source License

Declaration

public static boolean asBoolean(String str) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static boolean asBoolean(String str) {
        if (str == null || str.length() == 0)
            return false;
        str = str.trim();/*  ww  w.j  a  v a  2  s .c  om*/
        if ("1".equals(str))
            return true;
        str = str.toLowerCase();
        return "true".equals(str) || "yes".equals(str) || "y".equals(str) || "on".equals(str) || "ja".equals(str)
                || "enable".equals(str);
    }

    public static String toLowerCase(final String s) {
        return hasUpperLetter(s) ? s.toLowerCase() : s;
    }

    public static boolean hasUpperLetter(final CharSequence s) {
        int len;
        if (null != s && (len = s.length()) != 0)
            while (len > 0)
                if (Character.isUpperCase(s.charAt(--len)))
                    return true;
        return false;
    }
}

Related

  1. asBoolean(String flag)
  2. asBoolean(String name, boolean value)
  3. asBoolean(String s)
  4. asBoolean(String string)
  5. asBoolean(String value)
  6. asBoolean(String value, boolean defaultValue)
  7. atob(final String str, final boolean def)