Here you can find the source of xor(boolean val1, boolean val2)
Parameter | Description |
---|---|
val1 | first boolean value |
val2 | second boolean value |
public static boolean xor(boolean val1, boolean val2)
//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; } }