Returns true if all elements are true otherwise false. - Java java.lang

Java examples for java.lang:boolean

Description

Returns true if all elements are true otherwise false.

Demo Code


//package com.java2s;

public class Main {
    /**/*from w  w  w.ja v  a 2s  .  co  m*/
     * Returns true if all elements are true otherwise false.
     */
    public static boolean and(boolean[] values) {
        if (values == null) {
            return false;
        }
        for (boolean value : values) {
            if (!value) {
                return false;
            }
        }
        return true;
    }

    /**
     * Returns true if all elements are true otherwise false.
     */
    public static boolean and(Boolean[] values) {
        if (values == null) {
            return false;
        }
        for (Boolean value : values) {
            if (value == null || !value) {
                return false;
            }
        }
        return true;
    }
}

Related Tutorials