Java boolean Array

It is used to store boolean data type values only. With the following examples you can learn how to declare boolean array, how to assign values to boolean array and how to get values from boolean array.

boolean Array Example
/* boolean Array Example */
/* Save with file name BooleanArray.java */

public class BooleanArray
{
	public static void main(String args[])
	{
		//BOOLEAN ARRAY DECLARATION
		boolean b[];
		//MEMORY ALLOCATION FOR BOOLEAN ARRAY
		b = new boolean[4];
		//ASSIGNING ELEMENTS TO BOOLEAN ARRAY
		b[0] = true;
		b[1] = false;
		b[2] = false;
		b[3] = false;
		//BOOLEAN ARRAY OUTPUT
		System.out.println();
		System.out.println("boolean Array Example");
		System.out.println("=====================");
		System.out.println();
		for(int i=0;<b.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + b[i]);
		}
	}
}
                        

In this example you can learn how to assign values to boolean array at the time of declaration.

boolean Array Example 2
/* boolean Array Example 2 */
/* Save with file name BooleanArray2.java */

public class BooleanArray2
{
	public static void main(String args[])
	{
		//BOOLEAN ARRAY DECLARATION AND ASSIGNMENT
		boolean b[] = {false,false,true,true};
		//BOOLEAN ARRAY OUTPUT
		System.out.println();
		System.out.println("boolean Array Example");
		System.out.println("=====================");
		System.out.println();
		for(int i=0;i<b.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + b[i]);
		}
	}
}
                        

In this example you can learn how to declare boolean array with other boolean variables.

boolean Array Example 3
/* boolean Array Example 3 */
/* Save with file name BooleanArray3.java */

public class BooleanArray3
{
	public static void main(String args[])
	{
		//BOOLEAN ARRAY DECLARATION WITH OTHER NORMAL VARIABLES
		boolean b[], a; //b IS AN ARRAY a IS NOT AN ARRAY
		//ASSIGN VALUES TO BOOLEAN ARRAY
		b = new boolean[5];
		b[0] = true;
		b[1] = false;
		b[2] = false;
		b[3] = false;
		a = true;
		//BOOLEAN ARRAY OUTPUT
		System.out.println();
		System.out.println("boolean Array Example");
		System.out.println("=====================");
		System.out.println();
		System.out.println("a value is : "+a);
		System.out.println();
		for(int i=0;i<b.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + b[i]);
		}
	}
}
                        

In this example you can learn how to assign boolean array to other boolean array.

boolean Array Example 4
/* boolean Array Example 4 */
/* Save with file name BooleanArray4.java */

public class BooleanArray4
{
	public static void main(String args[])
	{
		//BOOLEAN ARRAYS DECLARATION
		boolean[] a, b; //a AND b ARE ARRAY VARIABLES
		//ASSIGN VALUES TO BOOLEAN ARRAY
		b = new boolean[5];
		b[0] = true;
		b[1] = false;
		b[2] = false;
		b[3] = false;
		//ASSIGNING b ARRAY TO a ARRAY VARIABLE
		a = b;
		//BOOLEAN ARRAY OUTPUT
		System.out.println();
		System.out.println("boolean Array Example");
		System.out.println("=====================");
		System.out.println();
		System.out.println("b array values");
		for(int i=0;i<b.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + b[i]);
		}
		System.out.println();
		System.out.println("a array values");
		for(int i=0;i<b.length;i++)
		{
			System.out.println("Element at Index : "+ i + " " + a[i]);
		}
	}
}