Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #166 Concatenate two lists

Create the list ab containing all the elements of the list a, followed by all the elements of the list b.

var ab = a + b;
(def ab (concat a b))
auto ab = a;
ab.insert (ab.end (), b.begin (), b.end ());
System.Linq
var list1 = new List<int>(){1,2,3};
var list2 = new List<int>(){4,5,6};

var list3 = list1.Concat(list2);
int[] a, b;
auto ab = a ~ b;
std.range;
int[] a, b;
auto ab = chain(a, b);
ab = a ++ b
AB = A ++ B.
real, dimension(:), allocatable :: ab

ab = [a, b]
var ab []T
ab = append(append(ab, a...), b...)
ab := append(a, b...)
ab := make([]T, len(a)+len(b))
copy(ab, a)
copy(ab[len(a):], b)
ab = a ++ b
var ab = a.concat(b);
var ab = new ArrayList<>(a);
ab.addAll(b);
val ab = a + b
(setf ab (append a b))
ab = {}

table.foreach(a, function(k, v) table.insert(ab, v) end)
table.foreach(b, function(k, v) table.insert(ab, v) end)
ab = {}

table.move(a, 1, #a, 1, ab)
table.move(b, 1, #b, #ab + 1, ab)
@import Foundation;
NSArray *ab=[a arrayByAddingObjectsFromArray:b];
$ab = array_merge($a, $b);
uses classes;
var
  a,b,ab: TList;

...
  ab := TList.Create;
  ab.Assign(a);
  ab.AddList(b);
...
@ab = (@a, @b)
ab = a + b
ab = a + b
let ab = [a, b].concat();
val ab = a ::: b
val ab = a ++ b
(define ab (append a b))
ab := a,b

New implementation...