0

I just took up Java and was wondering. Let's say I have an array (in my case multidimensional) and I wanted to make a copy of it but using a different variable, e.g. I have a boolean array

boolean[][] arrBool = [2][3]

and I wanted to create an int array of the same dimensions

int[][] arrInt= [2][3]

array. What would the simplest way to do this be?

Thanks

2 Answers 2

4

Use length, it returns the length of an array

int[][] arrInt = new int[arrBool.length][arrBool[0].length]
Sign up to request clarification or add additional context in comments.

1 Comment

A minimum explaination may be useful sometimes.
3

Just as you'd think you would

boolean[][] arrBool = new boolean[2][3];
int[][] arrInt = new int[2][3];

But I guess you probably mean what if the dimensions are dynamic. Then you could do

boolean[][] arrBool = ...;
int[][] arrInt = new int[arrBool.length][arrBool[0].length];

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.