File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "array" Watch "array" New topic


Sanjay Saxena
Ranch Hand

Joined: Dec 12, 2001
Posts: 81
I have a string array SA1 = {"AAA", "BBB", "CCC"};
and another array SA2 = {"DDD", "EEE", "FFF"};
Now I want to concatenate SA1 and SA2 to get a third array SA3 = {"AAA", "BBB", "CCC", "DDD", "EEE", "FFF"};
Can anybody tell me how to do this?
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
You'll need to declare a third array that is the length of the sum of the lengths of the original two arrays. Then, you could write a for-loop or two and copy each component from the two source arrays into the new destination array, but it would probably be easier and faster to make use of System.arraycopy.
Any luck?

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: array
jQuery in Action, 3rd edition