Append one array to another array

Joined
Jul 6, 2007
Messages
2
Reaction score
0
appendArrays (use addAll not add)

I think you meant to use addAll, as in:
/**
* @param array1
* @param array2
* @return a new array containing the contents of array1 followed by the contents of array2.
*/
public String[] appendArrays (String[]array1, String[] array2) {
ArrayList<String> temp =
new ArrayList<String>(array1.length + array2.length);
temp.addAll(Arrays.asList(array1));
temp.addAll(Arrays.asList(array2));
String[] result = (String[]) temp.toArray(new String[temp.size()]);
return result;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top