Java Boolean From toBoolean(Object obj)

Here you can find the source of toBoolean(Object obj)

Description

to Boolean

License

Apache License

Declaration

public static Boolean toBoolean(Object obj) throws IllegalArgumentException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static Boolean toBoolean(Object obj) throws IllegalArgumentException {
        if (obj == null) {
            throw new IllegalArgumentException("obj is null");
        }//  w  ww.j a va 2  s. c om

        if (obj instanceof Boolean) {
            return (Boolean) obj;
        }

        if (obj instanceof String) {
            String str = (String) obj;
            return new Boolean(str.equalsIgnoreCase("true") || str.equalsIgnoreCase("t")
                    || str.equalsIgnoreCase("y") || str.equalsIgnoreCase("yes") || str.equalsIgnoreCase("1"));
        }

        throw new IllegalArgumentException("Unable to convert object of type '" + obj.getClass() + "' to Boolean.");
    }
}

Related

  1. toBoolean(Object o)
  2. toBoolean(Object o)
  3. toBoolean(Object o)
  4. toBoolean(Object o)
  5. toBoolean(Object obj)
  6. toBoolean(Object obj)
  7. toBoolean(Object obj)
  8. toBoolean(Object obj)
  9. toBoolean(Object obj)