parse value to boolean - Android java.lang

Android examples for java.lang:String Parse

Description

parse value to boolean

Demo Code


//package com.java2s;
import android.text.TextUtils;

public class Main {
    /**// ww  w  .j  a va  2s  .  c om
     * parse value to boolean
     */
    public static boolean toBoolean(Object value) {
        if (value instanceof Boolean) {
            return (Boolean) value;
        }
        return value == null ? false : toBoolean(String.valueOf(value));
    }

    /**
     * parse value to boolean
     */
    public static boolean toBoolean(String value) {
        return TextUtils.isEmpty(value) ? false : Boolean
                .parseBoolean(value);
    }
}

Related Tutorials