An ordered list of elements

Methods

add (val:T):Void

Adds val to the end of the list.

get (index:Int):T

Returns the value at the given index.

getRange (fromIndex:Int, toIndex:Int):List<T>

Returns a shallow copy of a range of elements in the interval [fromIndex, toIndex). If toIndex is negative, the value represents the number of elements.

indexOf (val:T):Int

Returns the index of the first occurrence of val, or -1 if this list does not contain val.

insert (index:Int, val:T):Void

Inserts val at the specified index.

Shifts the element currently at that position (if any) and any subsequent elements to the right (indices + 1). If index equals Collection.size, val gets appended to the end of the list.

removeAt (index:Int):T

Removes the value at the given index.

set (index:Int, val:T):Void

Overwrites the value at the given index with val.

Inherited Variables

Defined by Collection

read onlysize:Int

The total number of elements in this collection.

Defined by Hashable

read onlykey:Int

A unique, unsigned 32-bit integer key.

A hash table transforms this key into an index of an array element by using a hash function.

Inherited Methods

Defined by Collection

@:value({ gc : false })clear (gc:Bool = false):Void

Removes all elements from this collection.

For performance reasons, elements are not nullified upon removal.

This means that elements won't be available for the garbage collector immediately unless gc is true.

Parameters:

gc

if true, elements are nullifies upon removal (slower).

@:value({ copier : null, byRef : true })clone (byRef:Bool = true, ?copier:T ‑> T):Collection<T>

Duplicates this collection.

Supports shallow (structure only) and deep copies (structure & elements).

Example:

class Element implements polygonal.ds.Cloneable<Element> {
    public var val:Int;
    public function new(val:Int) {
        this.val = val;
    }
    public function clone():Element {
        return new Element(val);
    }
}

...

var c:Collection<Element> = new Array2<Element>(...);

//shallow copy
var o = c.clone(true);

//deep copy
var o = c.clone(false);

//deep copy using a custom function
var o = c.clone(false, function(x) return new Element(x.val));

If byRef is true, primitive elements are copied by value whereas objects are copied by reference.

If byRef is false, the copier function is used for copying elements. If omitted, clone() is called on each element assuming all elements implement Cloneable.

contains (val:T):Bool

Returns true if this collection contains val.

free ():Void

Disposes this collection by explicitly nullifying all internal references for GC'ing used resources.

Improves GC efficiency/performance (optional).

isEmpty ():Bool

Returns true if this collection is empty.

iterator ():Itr<T>

Iterates over all elements in this collection.

Example:

var c = new ArrayList<String>();
for (element in c) trace(element);

//or
var c = new ArrayList<String>();
var itr = c.iterator();
while (itr.hasNext()) trace(itr.next());

//inline hasNext() and next()
var c = new ArrayList<String>();
var itr:ArrayListIterator<String> = cast c.iterator();
while (itr.hasNext()) trace(itr.next());

See:

remove (val:T):Bool

Removes all occurrences of val.

Returns:

true if at least one occurrence of val was removed.

toArray ():Array<T>

Returns an array storing all elements in this collection.