permaculture playing cards*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Resize the multi dimension array" Watch "Resize the multi dimension array" New topic
Author

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
Greenhorn

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,
[PT]Devilishly
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,
Barry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Resize the multi dimension array