Array
Array myArrayList myList
Description
A dynamic, ordered collection of values. Both Array and List are identical — List is just an alias.
An Array can hold any combination of types (bool, int, float, string, File, etc.) in the same instance.
Elements are zero-indexed.
Methods
| Method | Returns | Description |
|--------|---------|-------------|
| add(value) | void | Appends a copy of value to the end |
| get(index) | T | Returns a copy of the element at index |
| set(index, value) | void | Replaces the element at index with a copy of value |
| remove(index) | void | Removes the element at index |
| size() | int | Returns the number of elements |
| length() | int | Alias for size() |
| isEmpty() | bool | Returns true if the array contains no elements |
| clear() | void | Removes all elements |
| contains(value) | bool | Returns true if value is present in the array |
| indexOf(value) | int | Returns the index of the first match, or -1 if not found |
| first() | T | Returns a copy of the first element (error if empty) |
| last() | T | Returns a copy of the last element (error if empty) |
Example
void main()
{
Array names;
names.add("Alice");
names.add("Bob");
names.add("Charlie");
int n = names.size(); // 3
string s = names.get(1); // "Bob"
names.set(0, "Anna"); // replaces "Alice"
names.remove(2); // removes "Charlie"
bool has = names.contains("Bob"); // true
int idx = names.indexOf("Bob"); // 1
string f = names.first(); // "Anna"
string l = names.last(); // "Bob"
names.clear();
bool empty = names.isEmpty(); // true
// Gemischte Typen
List mixed;
mixed.add(42);
mixed.add(3.14);
mixed.add("hello");
mixed.add(true);
int count = mixed.length(); // 4
}