Forums Register Login
Appending two Multidimensional Arrays together

I've run into a challenge that I'm having problems solving. I'm curious to know if anybody out there has any experience with trying to append two multidimensional String arrays into one.

I've seen nothing relevant on the internet, other than just basic deep copies.

Any help or direction would be greatly appreciated!



I've seen nothing relevant on the internet, other than just basic deep copies.

Well, since you can't change the size of an array once it has been declared, the only relevant solution is to declare a new array, of a size that can hold both arrays, and copying the two source arrays into it.

Thanks for the reply.

I guess what I'm asking is how would you go about combining or appending two multidimensional arrays together. I've been unable to find any kind of example. Or clue on how to do this other than just a straight one to one copy.

Is this possible?

Thank you.
What do you mean by combine? Can you give us a short snippet of some sample data and what your expected result would be?
The intent behind the code is : I'm attempting to parse multiple csv files. The CSVParser in the program outputs the parse into a multidimensional String array. For each CSV file I process, I'd like to add the individual files into a Big One. Essentially, I need to add the contents of one Multidimensional Array to another.

I don't really have any data at this time to show you, It's more of a concept at this time. I just wanted to know if it was possible.

If I'm not being clear i apologize. I do appreciate your help.

Thank you!


I just wanted to know if it was possible.

Of course, it's possible. But as mentioned, you can't add (append) one array to the other, you have to create a third array, and copy the two arrays into it.

As for how, for that, you need to answer Martijn's question first... we don't have a clue what you want.

The issue here is that 'adding two multi-dimensional arrays' is not well defined.

Imagine i have two documents printed on paper, and i want to 'combine them'. do i

a) place document 'A' on top of 'B'?
b) Shuffle them together like a deck of cards, so i have A.page1 followed by B.page1 followed by A.page2...
c) Do I cut-n-past the contents of B.page1 physically onto A.page1
d) do i drop both into the paper shredder and mix up the resulting scraps?

All of these are valid ways of 'combining two paper documents' - each would be appropriate in certain situations.

The analogy is similar for what you are asking. We're not sure how exactly you would want to combine your arrays, so specific help is hard to give.
Thank you all for your reply's:

I'm not trying to be dense, I'm just not sure how to describe this. The two documents would be similar to this...

The program in question would parse each file into it's own multidimensional String array.

I would like to take both of these Multidimensional String arrays and put them together into another multidimensional array.....

This would be the desired content of the "third multidimensional array....

The third array would be an "accumulation" of all the data from all the different arrays...

Is this a better explanation?

It looks like you just want to append the contents of 2 on the end of contents from 1. A simply array copy into the new array (sized as mentioned above by others) will do the trick for this.
So something like this would work...


So something like this would work...

Sure... provided that you instantiate the third array. And pass the right parameters to the arraycopy() method (the parameters in your example are obviously wrong).

Thank you for your help!!

This thread has been viewed 5605 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 22, 2018 11:27:39.