Java Boolean From toBoolean(Object object)

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

Description

Converts an object to a boolean (return false if the conversion fail)

License

Open Source License

Parameter

Parameter Description
object the object

Return

the boolean

Declaration

public static boolean toBoolean(Object object) 

Method Source Code

//package com.java2s;
/*/*  www  .j  ava 2s  .  co m*/
Mini Focused Crawler : focused web crawler with a simple GUI
Copyright (C) 2013  lbertelo
    
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Converts an object to a boolean (return false if the conversion fail)
     * @param object the object
     * @return the boolean
     */
    public static boolean toBoolean(Object object) {
        if (object instanceof Boolean) {
            return ((Boolean) object).booleanValue();
        } else if (object instanceof String) {
            return Boolean.parseBoolean((String) object);
        } else {
            return false;
        }
    }
}

Related

  1. toBoolean(Object obj)
  2. toBoolean(Object obj)
  3. toBoolean(Object obj)
  4. toBoolean(Object obj)
  5. toBoolean(Object obj)
  6. toBoolean(Object object)
  7. toBoolean(Object object)
  8. toBoolean(Object object)
  9. toBoolean(Object object, Boolean defaultValue)