2

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?

4
  • Casts are your only bet, but why do you have a heterogeneous array to begin with? Commented Nov 28, 2016 at 3:58
  • you probably mean second column when you say [i][1]. Just wondering. Commented Nov 28, 2016 at 3:58
  • System.out.println(((Object) true).getClass()); Commented Nov 28, 2016 at 4:01
  • @Makoto, I have used it to create JTable. And i just don't want to declare new class with Object and boolean attributes. Commented Nov 28, 2016 at 4:06

1 Answer 1

4

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];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.