• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Appending two Multidimensional Arrays together

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
author
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
B West
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by combine? Can you give us a short snippet of some sample data and what your expected result would be?
 
B West
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
lowercase baba
Posts: 13002
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
B West
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So something like this would work...


 
Henry Wong
author
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your help!!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic