1

We are working on a lab assignment for my CS&E class and I think I can ask this question without going into detail of the entire lab requirements, but is it possible for an array to be inside of an array? For example, would this work:

int [] arrayOne = new int[3];

arrayOne[0] = Start of an array

If this is possible how do you go about doing it?

4 Answers 4

2

sure

int[][] array2d = new int[3][];
for (int i = 0; i < array2d.length; ++i)
    array2d[i] = new int[4];
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I now found the chapter in my Java book and hopefully I can take it from here. But thanks again for the quick response!
2

Well, the way you put it, it won't work, you have to declare arrayOne to be a multidimensional array, just like this:


int arrayOne [][] = new int[3][];
arrayOne [0] = new int[5];

if you declare your array like this:


int [] arrayOne = new int[3];

arrayOne will be able to store only the int type, but when you declare it like i said, means that each element in arrayOne can hold another array of the int type;

1 Comment

Thank you! I now found the chapter in my Java book and hopefully I can take it from here. But thanks again for the quick response!
0

use 2 dimensional array.

int[][] arrayOne = new int[3][];
arrayOne[0] = new int[3];

Comments

0

You are looking for arrays of arrays also called multi-dimensional arrays which are described in The Java Tutorial page about arrays.

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.