Array concatenation: Difference between revisions
Content added Content deleted
(→{{header|Java}}: consistent formatting, removed dead link) |
|||
Line 1,438: | Line 1,438: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
<lang java5>public static Object[] concat(Object[] arr1, Object[] arr2) { |
|||
From [http://forums.sun.com/thread.jspa?messageID=1762690#1762690]: |
|||
Object[] res = new Object[arr1.length + arr2.length]; |
|||
{ |
|||
Object[] ret = new Object[o1.length + o2.length]; |
|||
System.arraycopy( |
System.arraycopy(arr1, 0, res, 0, arr1.length); |
||
System.arraycopy( |
System.arraycopy(arr2, 0, res, arr1.length, arr2.length); |
||
⚫ | |||
⚫ | |||
⚫ | |||
Or with <code>Collection</code>s simply call <code>addAll</code>: |
|||
⚫ | |||
<lang java5>Collection list1, list2, list1And2; |
|||
//...list1 and list2 are instantiated... |
|||
list1And2 = new ArrayList(list1); //or any other Collection you want |
|||
list1And2.addAll(list2);</lang> |
|||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |