List CLASS

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

All Members


TypeNameSignature
constructorListpublic List()
methodaddpublic void add(var)
methodatpublic var at(var)
methodatpublic void at(var, var)
methodgetpublic var get(int)
methodgetIteratorpublic IIterator getIterator()
methodputpublic void put(int, var)
methodremovepublic var remove(int)
methodsizepublic int size()
methodsortpublic void sort(bool)
methodtoArraypublic var[] toArray()

Constructors


public List()

Create a new and empty List object, with default capacity.


Methods


public void add(var element)

Add an item at the end of the list. This operation increase the size by 1.

Parameters

  • element The element to add. This element can be null and of any type.

public var at(var index)

Parameters

  • index

Returns


public void at(var index, var value)

Parameters

  • index

  • value

public var get(int index)

Get the item at the specified index.

Parameters

  • index The index at which the item will be returned.

Returns

  • The value stored under this index.

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

  • index The index at which the item will be returned.
  • value

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

  • index The index at which the item will be removed.

Returns

  • The removed item.

Throws


public int size()

Returns

  • The size of list.

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

  • descending if false, use the natural ascending order, i.e. the smaller values are placed ahead of larger values; if true, reverse the order.

public var[] toArray()

Convert to an array of Any.

Returns

  • A list of Any.