10.2.3 List

A List is a collection for storing elements. On the surface, a list is similar to an Array. However, the underlying implementation is very different. This results in several functional differences:

  1. A list cannot be indexed using square brackets, i.e. [0].
  2. A list cannot be initialized.
  3. There are no list comprehensions.
  4. A list can freely modify/add/remove elements while iterating over them.

A simple example of working with lists:

class Main {
  static public function main() {
    var myList = new haxe.ds.List<Int>();
    for (ii in 0...5)
      myList.add(ii);
    trace(myList); // {0, 1, 2, 3, 4}
  }
}
Related content