Java xor xor(boolean val1, boolean val2)

Here you can find the source of xor(boolean val1, boolean val2)

Description

Returns (val1 != val2).

License

MIT License

Parameter

Parameter Description
val1 first boolean value
val2 second boolean value

Return

true if the arguments are different and false otherwise

Declaration

public static boolean xor(boolean val1, boolean val2) 

Method Source Code

//package com.java2s;
/*!//w  w  w . ja v  a 2 s.c om
 * mifmi-commons4j
 * https://github.com/mifmi/mifmi-commons4j
 *
 * Copyright (c) 2015 mifmi.org and other contributors
 * Released under the MIT license
 * https://opensource.org/licenses/MIT
 */

public class Main {
    /**
     * Returns (val1 != val2).
     * 
     * @param val1 first boolean value
     * @param val2 second boolean value
     * @return true if the arguments are different and false otherwise
     */
    public static boolean xor(boolean val1, boolean val2) {
        return (val1 != val2);
    }

    /**
     * Returns (vals[0] != vals[1] != vals[2] != ...).
     * 
     * @param vals boolean values
     * @return true if the arguments are different and false otherwise
     */
    public static boolean xor(boolean... vals) {
        if (vals == null || vals.length == 0) {
            return false;
        }

        boolean b = vals[0];
        for (int i = 1; i < vals.length; i++) {
            if (vals[i] != b) {
                return true;
            }
        }

        return false;
    }
}

Related

  1. xor(boolean a, boolean b)
  2. xor(boolean a[], boolean b[])
  3. xor(boolean b1, boolean b2)
  4. xor(boolean b1, boolean b2)
  5. xor(boolean o, boolean t)
  6. xOr(boolean x, boolean y)
  7. xor(boolean... bools)
  8. xor(boolean[] array)
  9. xor(boolean[][] b1, boolean[][] b2)