Java Object Convert to objToBoolean(Object o)

Here you can find the source of objToBoolean(Object o)

Description

obj To Boolean

License

Apache License

Declaration

static public boolean objToBoolean(Object o) 

Method Source Code

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

public class Main {

    static public boolean objToBoolean(Object o) {
        if (o != null) {
            if (o instanceof Boolean)
                return ((Boolean) o).booleanValue();
            else if (o instanceof String) {
                String s = (String) o;
                if (s.equalsIgnoreCase("true"))
                    return true;
                if (s.equalsIgnoreCase("false"))
                    return false;
                if (s.equals("1"))
                    return true;
                if (s.equals("0"))
                    return false;
            } else if (o instanceof Integer) {
                Integer i = (Integer) o;
                if (1 == i)
                    return true;
                if (0 == i)
                    return false;
            }//from   w  ww.j  a v a  2  s  .c o m
        }
        return false;
    }
}

Related

  1. objToLong(Object obj)
  2. objToPrim()
  3. objToTimeLong(Object obj)