A list is a serial, self-scalable data structure that can grow its capacity on demand. This class is backed by a dynamically re-allocated platform array, which is not exposed through the API. The underlying implementation implies that the position-based operation can be costly, especially when the size grows significantly.
The list is iterable with the following syntax: for (var a : list) {
... ... // can access element (a), but not update list
}
The methods of this class are thread safe.
Parent Class
Parent Interfaces
Type | Name | Signature |
---|---|---|
constructor | List | public List() |
method | add | public void add(var) |
method | at | public var at(var) |
method | at | public void at(var, var) |
method | get | public var get(int) |
method | getIterator | public IIterator getIterator() |
method | put | public void put(int, var) |
method | remove | public var remove(int) |
method | size | public int size() |
method | sort | public void sort(bool) |
method | toArray | public var[] toArray() |
public List()
Create a new and empty List object, with default capacity.
public void add(var element)
Add an item at the end of the list. This operation increase the size by 1.
Parameters
public var at(var index)
Parameters
Returns
public void at(var index, var value)
Parameters
public var get(int index)
Get the item at the specified index.
Parameters
Returns
Throws
public IIterator getIterator()
Returns
public void put(int index, var value)
Set the item at the specified index. The index must be within the range of current size.
Parameters
Throws
public var remove(int index)
Remove the item at the specified index. The index must be within the range of current size. Thie method will succeed even if the key doesn't exist.
Parameters
Returns
Throws
public int size()
Returns
public void sort(bool descending)
Sort this list in place.
This method relies on all the elements being comparable to everyone else. Even if there is a single pair of elements that cannot be compared to each other, the whole sorting process may silently fail, immaturely abort, or end with nondeterministic results.
For primitive and built-in types, string and char are comparable to each other; int, byte and float are comparable among themselves. For an Object type, it must implement IComparable interface. The user must ensure that the implementation of this interface covers all the possible types of elements that may be found in the list.
Parameters
public var[] toArray()
Convert to an array of Any.
Returns