Java – Populates two-dimensional arrays with boolean values

Populates two-dimensional arrays with boolean values… here is a solution to the problem.

Populates two-dimensional arrays with boolean values

I have these attributes in my class:

boolean rendered[][] = new boolean[][]{};
String tabs[] = { "Tab 1", "Tab 2" };
int rows = 10;

… I want to create an array with two main levels (two elements in the tabs array), each with 10 (variable rows) elements with false values.

Solution

You can think of it as either [row][column] or [column][row], but the former has a history of use.

int rows = 10, int columns = 2
boolean rendered[][] = new boolean[rows][columns];
java.util.Arrays.fill(rendered[0], false);
java.util.Arrays.fill(rendered[1], false);

Related Problems and Solutions