ArrayList<E>.withCapacity constructor

ArrayList<E>.withCapacity(
  1. int initialCapacity
)

Creates an ArrayList with the specified initial capacity.

initialCapacity the initial capacity of the list

A resizable array implementation similar to Java's ArrayList.

This class provides a dynamic array that can grow and shrink as needed, with methods similar to Java's ArrayList.

Example usage:

ArrayList<String> list = ArrayList<String>();
list.add("Hello");
list.add("World");
list.insert(1, "Beautiful");

print(list.get(0)); // "Hello"
print(list.size()); // 3

Implementation

ArrayList.withCapacity(int initialCapacity)
    : _list = List<E>.empty(growable: true);