cotrGenList
Generates an array (list) of a specific length
Aliases:
- cotrGenList
- generateList
- listGen
cpp
std::vector<type> listName( size, initialValue );
csharp
var myList = Enumerable.Range(0, length).Select(i => 'item' + i.ToString()).ToList();
dart
var myList = List.generate(length, (index) => 'item' + index.toString());
go
var arrayName = []arrayType{ value1, value2}
haskell
[start..end]
java
List<Type> myList = IntStream.range(0, length).mapToObj(i -> value).collect(Collectors.toList());
javascript
const myList = Array.from({ length: length }, (_, index) => 'item' + index);
javascriptreact
const myList = Array.from({ length: length }, (_, index) => 'item' + index);
kotlin
val myList = List(length) { 'item' + it}
perl
my @listName = (initialValue) x length;
php
myArray = range(0, 10);
powershell
1..length | ForEach-Object { 'item' +_ }
ruby
my_array = Array.new(length) { |i| 'item' + i.to_s }
rust
let myList = [ 'item1', 'item2', // Add more items here];
shellscript
# Bash doesn't have built-in list generation, but you can use loops or command substitution:myList=((for i in {1..10}; do echo itei; done) )
swift
var myArray = Array(repeating: 'item', count: 5);
typescript
const myList = Array.from({ length: length }, (_, index) => 'item' + index);
typescriptreact
const myList = Array.from({ length: length }, (_, index) => 'item' + index);