File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Appending two Multidimensional Arrays together Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Appending two Multidimensional Arrays together" Watch "Appending two Multidimensional Arrays together" New topic
Author

Appending two Multidimensional Arrays together

B West
Greenhorn

Joined: Oct 10, 2008
Posts: 29
Hello

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!

Thanks
bw

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18120
    
  39

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.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
B West
Greenhorn

Joined: Oct 10, 2008
Posts: 29
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.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

What do you mean by combine? Can you give us a short snippet of some sample data and what your expected result would be?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
B West
Greenhorn

Joined: Oct 10, 2008
Posts: 29
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!







Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18120
    
  39

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.

Henry
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
B West
Greenhorn

Joined: Oct 10, 2008
Posts: 29
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?

Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

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.
B West
Greenhorn

Joined: Oct 10, 2008
Posts: 29
So something like this would work...


Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18120
    
  39

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).

Henry
B West
Greenhorn

Joined: Oct 10, 2008
Posts: 29
Thank you for your help!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Appending two Multidimensional Arrays together
 
Similar Threads
How to resize a multidimensional array?
expanding a multidimensional array?
multidimensional arrays, references and values. Need help understanding...
multidimensional array
multidimensional array