This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "array" Watch "array" New topic
Author

array

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
Sheriff

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]
 
Don't get me started about those stupid light bulbs.
 
subject: array