Q:

Make a Java boolean with a size of 1 bit

I am writing a program which necessitates speed and a low memory overhead. In it, I have to make a 2d array of booleans, which will likely get very big. 
In Java, I know that a boolean is an "overlay" to a char, so it takes up one byte.
Is there any way to make an array of booleans, each of which are only 1 bit, the storage space technically necessary. Thanks!

A:

As it was already mentioned, you can use primitives as an array of bits. That is not straight forward to work with, but at least it reduces the amount of data that you store.
With the magic of method convertToBinary that I found here:
Integer to binary array
We can work with such numbers easily. 
e.g. 
 public static void main(String[] args) {
    Integer[] flags = {
            0b0101_0101_0101_0101_0101_0101_0101_0101,
            0b0101_0101_0101_0101_0101_0101_0101_0101,
            0b0101_0101_0101_0101_0101_0101_0101_0101
    };
    for (Integer flag : flags) {
        System.out.println(Arrays.toString(getBooleanArray(flag)));
    }
}

private static boolean[] getBooleanArray(Integer value) {
    String valueAsString = Integer.toBinaryString(value).replaceFirst("^0+(?!$)", "");
    return convertToBinary(value, valueAsString.length());
}

private static boolean[] convertToBinary(int b, int size) {
    boolean[] binArray = new boolean[size];
    boolean bin;
    for (int i = size - 1; i >= 0; i--) {
        if (b % 2 == 1) bin = true;
        else bin = false;
        binArray[i] = bin;
        b /= 2;
    }
    return binArray;
}

Output:
[true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true]

[true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true]
[true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true]
Hope that helps. 

