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

Idiom #134 Create a new list

Declare and initialize a new list items, containing 3 elements a, b, c.

classes
var
  Items: TList;
  a,b,c: pointer;
begin
  Items := TList.Create;
  Items.Add(a);
  Items.Add(b);
  Items.Add(c);
end.
#include <vector>
std::vector<T> items = {a, b, c};
auto items = [a, b, c];
items = [a, b, c]
items := []T{a, b, c}
items = [a, b, c]
var items = [a, b, c];
var items = new Array(a, b, c);
import java.util.List;
import java.util.ArrayList;
List<T> items = new ArrayList<>();
items.add(a);
items.add(b);
items.add(c);
import java.util.List;
import java.util.Arrays;
List<T> items = Arrays.asList(a, b, c);
items = {a, b, c}
$items = [$a, $b, $c];
my @items = ($a, $b, $c);
items = [a, b, c]
items = [a, b, c]
let v_list = vec![a,b,c];
(define items (list a b c))

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms