- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we initialize a boolean array in Java?n
The boolean array can be used to store boolean datatype values only and the default value of the boolean array is false. An array of booleans are initialized to false and arrays of reference types are initialized to null. In some cases, we need to initialize all values of the boolean array with true or false. We can use the Arrays.fill() method in such cases.
Syntax
boolean[] booleanArray;
Example
import java.util.Arrays; public class BooleanArrayTest { public static void main(String[] args) { Boolean[] boolArray = new Boolean[5]; // initialize a boolean array for(int i = 0; i < boolArray.length; i++) { System.out.println(boolArray[i]); } Arrays.fill(boolArray, Boolean.FALSE); // all the values will be false for(int i = 0; i < boolArray.length; i++) { System.out.println(boolArray[i]); } Arrays.fill(boolArray, Boolean.TRUE); // all the values will be true for (int i = 0; i < boolArray.length; i++) { System.out.println(boolArray[i]); } } }
Output
null null null null null false false false false false true true true true true
- Related Articles
- How can we initialize a boolean array in Java?
- How to initialize a boolean array in JavaScript?
- Can we initialize blank final variable in Java
- How do we initialize an array within object parameters in java?
- Can we initialize static variables in a default constructor in Java?
- Initialize the mask to homogeneous boolean array by passing in a scalar boolean value in Numpy
- how to initialize a dynamic array in java?
- How to initialize an array in Java
- How can we enter BOOLEAN values in MySQL statement?
- How can we convert a JSONArray to String Array in Java?
- How can we convert character array to a Reader in Java?
- How to initialize an array in JShell in Java 9?
- How do we initialize a variable in C++?
- How can we make an Array of Objects from n properties of n arrays in JavaScript?
- How do I declare and initialize an array in Java?
- How to initialize an array using lambda expression in Java?

Advertisements