How to increase the 2-dimensional Array size dynamically.?

M

Mohan

Hi,

In my application, I need to increase the 2-dimensional array size
dynamically.

Please let me know the procedure to declare a dynamic 2-dimensional array
like Single dimensional array, ArrayList.

Thanks,
Mohan
 
O

Oliver Sturm

Mohan said:
In my application, I need to increase the 2-dimensional array size
dynamically.

Please let me know the procedure to declare a dynamic 2-dimensional array
like Single dimensional array, ArrayList.

An ArrayList, which can be dynamically increased in size, is not an
array. It's not possible to increase arrays in size dynamically,
regardless of the number of their dimensions.

Of course you could use an ArrayList of ArrayLists:

ArrayList outerList = new ArrayList();
outerList.Add(new ArrayList());
outerList.Add(new ArrayList());

Now you can access outerList[0] and outerList[1] and add arbitrary
numbers of objects to them, or you can extend outerList. So the complete
construction is effectively dynamically resizable in two dimensions.

Depending on the needs of your data storage, you should definitely look
at other solutions, though - it would be better to use typed
collections, for example, and although there are points where a solution
like this is required, I wonder if a more tightly integrated data
management class wouldn't be a better solution.


Oliver Sturm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top