473,465 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

multidimensional array problem

112 New Member
i want to store numbers in a grid. thats not the problem...i need to be able to store a variable amount of numbers at each location...originally i set up an int[][][] but the inflexibility of the array made some problems for me...what i need is something like this: int[][]() the ()being an arraylist or something of that nature. Something about this confuses me...is there a way to do that?

thanks
Apr 8 '08 #1
3 1155
BigDaddyLH
1,216 Recognized Expert Top Contributor
i want to store numbers in a grid. thats not the problem...i need to be able to store a variable amount of numbers at each location...originally i set up an int[][][] but the inflexibility of the array made some problems for me...what i need is something like this: int[][]() the ()being an arraylist or something of that nature. Something about this confuses me...is there a way to do that?

thanks
You can have an array of any type, including an array of lists. You can also define arrays piecemeal, like this:

Expand|Select|Wrap|Line Numbers
  1. int size = 5;
  2. int [][] triangle = new int[size][];
  3. for(int i=0; i<size; ++i) {
  4.     triangle[i] = new int[i+1];
  5. }
It's not clear from your post what your real problem is. If it's that you want an array to grow or shrink, that's usually a sign that you should go with a collection like a list instead.
Apr 8 '08 #2
drsmooth
112 New Member
yea ill try the arraylist way...thats wat i thought to do i just wasnt sure how it would work...wud i use grid[x][y].get(z)? i guess that makes sense

thanks alot
Apr 8 '08 #3
BigDaddyLH
1,216 Recognized Expert Top Contributor
yea ill try the arraylist way...thats wat i thought to do i just wasnt sure how it would work...wud i use grid[x][y].get(z)? i guess that makes sense

thanks alot
I'm not a big fan of mixing arrays and collections. Actually, I think if you analyze your problem further you'll want to start defining some classes. I've never had to nest arrays three deep: [][][]. Unless this is some specific math problem, I suppose, but I can only guess your domain.
Apr 8 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Rob Tweed | last post by:
Probably a simple question but I can't find the answer anyway. Specifically, is it possible to copy a multidimensional array into the $_SESSION array - ie a deep clone of all keys and data? I...
9
by: Georg Ringer | last post by:
Hi, I've got a multidimensional array which looks like this: $data = array('nname' => 'Auerbach', 'vname' => 'Berthold', 'uid' => 20); $data = array('nname' => 'Bloch', 'vname' => 'Ernst', 'uid'...
5
by: TLOlczyk | last post by:
I have a brain cramp and I need some help. I have a chunk of code below which demonstrates a problem I have with multidimensional arrays. I want to keep it simple but something specific is...
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
10
by: Ole | last post by:
Goodday everybody, i want to create an array that represents data, that has to be transferred to a pdf doc ( iTextSharp ). The problem is, that i seem too loose my faith. Namely, ( i have...
1
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a...
2
by: chris | last post by:
Hi there, I created a Multidimensional array of labels Label lblMultiArray = new Label { {Label3, LblThuTotal}, {Label4,LblFriTotal} }; Now I would like to compare the values in the array,...
14
by: Michel Rouzic | last post by:
Hi, I've recently met issues with my program which can only be explained by heap corruption, so I've tried debugging my program with Valgrind, and here's what I get with the following...
12
by: filippo nanni | last post by:
Hello everybody, my question is this: I have two multidimensional arrays and I have to create a third one (for later use) from comparing these two. Here is my example code: //BEGIN CODE var...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.