Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize a 2D Boolean Array with all elements False?

Tags:

java

The title describes the question. Here's the code:

boolean planeArray[][];
like image 214
Ray Bae Avatar asked Aug 15 '26 11:08

Ray Bae


2 Answers

Just with

boolean planeArray[][] = new boolean[rows][columns];

all values will be false by default.


You can also initialize with the number of rows:

boolean planeArray[][] = new boolean[rows][];

and then assign each row an 1D-array:

planeArray[0] = new boolean[columns];
...

Note that by using this last way, rows can have different number of columns.

like image 52
Christian Tapia Avatar answered Aug 16 '26 23:08

Christian Tapia


You have to initialize the array and the default value of boolean will be set to all the indexs element which is false.

boolean planeArray[][]  =  new boolean[row_size][column_size];
like image 20
Kick Avatar answered Aug 16 '26 23:08

Kick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!