Object to boolean conversion in Java

For example I have an array Object[][] array = Object[n][2]; Second row of this array contains an boolean data, due to:

for (int i = 0; i < array.length; i++){
     boolean bool = true;
     array[i][1] = bool;
}

Is it possible to convert an array[i][1], which is an object type, back to the boolean value?

Upvotes: 2

Views: 2657

Answers (1)

Asaph
Asaph

Reputation: 162781

You can use a cast to convert it back to a boolean type. For example, if array is declared as an Object[][] but contains a boolean type, you can do this:

boolean bool = (Boolean) array[0][1];

Upvotes: 4

Related Questions