This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread 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 Head First Android this week in the Android 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]
 
jQuery in Action, 3rd edition
 
subject: array
 
It's not a secret anymore!