Can be achieved using stream API in java 8 and above
public static boolean logicalXOR(boolean x, boolean y) { // can modify to take [] or list of bools return Stream.of(x, y) // modify as per method params .filter(bool -> bool) .count() == 1; } public static boolean logicalXOR(boolean x, boolean y) { // can modify to take [] or list of bools return Stream.of(x, y) // modify as per method params .filter(bool -> bool) .count() == 1; }