This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Resize the multi dimension array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Resize the multi dimension array" Watch "Resize the multi dimension array" New topic

Resize the multi dimension array

Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hi all,
I have this question,
say if I declare a 2D array for example;
int arr[][] = new int[2][2];

and declare a single dimensional array;
int x[] = new int[3];

so my question is that can I assign like this;

arr[1] = x;

Upto to my knowledge the size of the array once declared can't grow. But here it's not happening like that?
Could you please explain this to me,
Thank you in adavance.....

SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
Daniel Botelho

Joined: Nov 13, 2004
Posts: 6
so my question is that can I assign like this;

arr[1] = x;
I think so... :roll:

I've tryied this code and it does that:

Best regards,
Barry Higgins
Ranch Hand

Joined: Jun 05, 2003
Posts: 89
The fact that this is a multidimensional array has nothing to do with it.
Think of what you are doing you are declaring arr[1] (and arr[0]) to be a refence to a new array of ints.
You then assign this reference to the array of 2 ints.
When you create a new array of 3 ints you assign the same reference to this array.
These are two seperate arrays. You are not changing the size of either and you are right you cannot!
All you are doing is taking the reference from one array and assigning it to another!
Hope this helps,
I agree. Here's the link:
subject: Resize the multi dimension array