List<T>

Overview

Represents an ordered collection of objects that can be accessed by index.

Elements in this collection can be accessed using an integer index. Indexes in this collection are zero-based. List accepts nil as a valid value for reference types and allows duplicate elements.

Note: On Nougat platform list internally converts nil to the NSNull type.

Use case

You can use List class when you need to store a collection of objects and be able to access them by index.

var Items := new List<String>(["One", "Two", "Three"]);
  
for i: Integer := 0 to Items.Count - 1 do
  writeLn(Sugar.String.Format("[{0}]: {1}", i, Items[i]));

writeLn(Items.Contains("Two"));
Items.Remove("Two");
Items.Insert(1, "Second");
Items.ForEach(item -> writeLn(item));

Loops

Please note:* Instead of using for/each or for/in loops in the collections please use ForEach methods.

For example:

var Items := new List<String>(["One", "Two", "Three"]);
Items.ForEach(item -> DoSomething(item));  

Location

 

constructor (array of T)

Creates an instance of the class and copies items from the array.

 

constructor(anArray: array of T)

 

List<T>(T[] anArray)

 

init(_ anArray: T...)

 

List<T>(T[] anArray)

Parameters:

  • anArray: Array that stores items which needs to be copied.

constructor (List<T>)

 

constructor(Items: List<T>)

 

List<T>(List<T> Items)

 

init(_ Items: List<T>)

 

List<T>(List<T> Items)

Parameters:

  • Items:

Add  mapped

 

method Add(anItem: T)

 

void Add(T anItem)

 

func Add(_ anItem: T)

 

void Add(T anItem)

Parameters:

  • anItem:

AddRange (array of T)  mapped

 

method AddRange(Items: array of T)

 

void AddRange(T[] Items)

 

func AddRange(_ Items: T...)

 

void AddRange(T[] Items)

Parameters:

  • Items:

AddRange (List<T>)  mapped

 

method AddRange(Items: List<T>)

 

void AddRange(List<T> Items)

 

func AddRange(_ Items: List<T>)

 

void AddRange(List<T> Items)

Parameters:

  • Items:

Clear  mapped

 

method Clear

 

void Clear()

 

func Clear()

 

void Clear()

Contains  mapped

 

method Contains(anItem: T): Boolean

 

Boolean Contains(T anItem)

 

func Contains(_ anItem: T) -> Boolean

 

Boolean Contains(T anItem)

Parameters:

  • anItem:

Count

 

property Count: Int32 read;

 

Int32 Count { get; }

 

var Count: Int32 { get{} }

 

Int32 Count { __get; }

Exists  mapped

 

method Exists(Match: Predicate<T>): Boolean

 

Boolean Exists(Predicate<T> Match)

 

func Exists(_ Match: Predicate<T>) -> Boolean

 

Boolean Exists(Predicate<T> Match)

Parameters:

  • Match:

Find  mapped

 

method Find(Match: Predicate<T>): T

 

T Find(Predicate<T> Match)

 

func Find(_ Match: Predicate<T>) -> T

 

T Find(Predicate<T> Match)

Parameters:

  • Match:

FindAll  mapped

 

method FindAll(Match: Predicate<T>): List<T>

 

List<T> FindAll(Predicate<T> Match)

 

func FindAll(_ Match: Predicate<T>) -> List<T>

 

List<T> FindAll(Predicate<T> Match)

Parameters:

  • Match:

FindIndex (Predicate<T>): Int32  mapped

 

method FindIndex(Match: Predicate<T>): Int32

 

Int32 FindIndex(Predicate<T> Match)

 

func FindIndex(_ Match: Predicate<T>) -> Int32

 

Int32 FindIndex(Predicate<T> Match)

Parameters:

  • Match:

FindIndex (Int32, Predicate<T>): Int32  mapped

 

method FindIndex(StartIndex: Int32; Match: Predicate<T>): Int32

 

Int32 FindIndex(Int32 StartIndex, Predicate<T> Match)

 

func FindIndex(_ StartIndex: Int32, _ Match: Predicate<T>) -> Int32

 

Int32 FindIndex(Int32 StartIndex, Predicate<T> Match)

Parameters:

  • StartIndex:
  • Match:

FindIndex (Int32, Int32, Predicate<T>): Int32  mapped

 

method FindIndex(StartIndex: Int32; aCount: Int32; Match: Predicate<T>): Int32

 

Int32 FindIndex(Int32 StartIndex, Int32 aCount, Predicate<T> Match)

 

func FindIndex(_ StartIndex: Int32, _ aCount: Int32, _ Match: Predicate<T>) -> Int32

 

Int32 FindIndex(Int32 StartIndex, Int32 aCount, Predicate<T> Match)

Parameters:

  • StartIndex:
  • aCount:
  • Match:

ForEach  mapped

 

method ForEach(Action: Action<T>)

 

void ForEach(Action<T> Action)

 

func ForEach(_ Action: Action<T>)

 

void ForEach(Action<T> Action)

Parameters:

  • Action:

GetItem  mapped

 

method GetItem(Index: Int32): T

 

T GetItem(Int32 Index)

 

func GetItem(_ Index: Int32) -> T

 

T GetItem(Int32 Index)

Parameters:

  • Index:

IndexOf  mapped

 

method IndexOf(anItem: T): Int32

 

Int32 IndexOf(T anItem)

 

func IndexOf(_ anItem: T) -> Int32

 

Int32 IndexOf(T anItem)

Parameters:

  • anItem:

Insert  mapped

 

method Insert(Index: Int32; anItem: T)

 

void Insert(Int32 Index, T anItem)

 

func Insert(_ Index: Int32, _ anItem: T)

 

void Insert(Int32 Index, T anItem)

Parameters:

  • Index:
  • anItem:

InsertRange (Int32, array of T)  mapped

 

method InsertRange(Index: Int32; Items: array of T)

 

void InsertRange(Int32 Index, T[] Items)

 

func InsertRange(_ Index: Int32, _ Items: T...)

 

void InsertRange(Int32 Index, T[] Items)

Parameters:

  • Index:
  • Items:

InsertRange (Int32, List<T>)  mapped

 

method InsertRange(Index: Int32; Items: List<T>)

 

void InsertRange(Int32 Index, List<T> Items)

 

func InsertRange(_ Index: Int32, _ Items: List<T>)

 

void InsertRange(Int32 Index, List<T> Items)

Parameters:

  • Index:
  • Items:

Item

 

property Item[i: Int32]: T read write;

 

T Item[Int32 i] { get; set; }

 

subscript Item(_ i: Int32) -> T { get{} set{} }

 

T Item[Int32 i] { __get; __set; }

LastIndexOf  mapped

 

method LastIndexOf(anItem: T): Int32

 

Int32 LastIndexOf(T anItem)

 

func LastIndexOf(_ anItem: T) -> Int32

 

Int32 LastIndexOf(T anItem)

Parameters:

  • anItem:

Remove  mapped

 

method Remove(anItem: T): Boolean

 

Boolean Remove(T anItem)

 

func Remove(_ anItem: T) -> Boolean

 

Boolean Remove(T anItem)

Parameters:

  • anItem:

RemoveAt  mapped

 

method RemoveAt(Index: Int32)

 

void RemoveAt(Int32 Index)

 

func RemoveAt(_ Index: Int32)

 

void RemoveAt(Int32 Index)

Parameters:

  • Index:

RemoveRange  mapped

 

method RemoveRange(Index: Int32; aCount: Int32)

 

void RemoveRange(Int32 Index, Int32 aCount)

 

func RemoveRange(_ Index: Int32, _ aCount: Int32)

 

void RemoveRange(Int32 Index, Int32 aCount)

Parameters:

  • Index:
  • aCount:

SetItem  mapped

 

method SetItem(Index: Int32; Value: T)

 

void SetItem(Int32 Index, T Value)

 

func SetItem(_ Index: Int32, _ Value: T)

 

void SetItem(Int32 Index, T Value)

Parameters:

  • Index:
  • Value:

Sort  mapped

 

method Sort(Comparison: Comparison<T>)

 

void Sort(Comparison<T> Comparison)

 

func Sort(_ Comparison: Comparison<T>)

 

void Sort(Comparison<T> Comparison)

Parameters:

  • Comparison:

ToArray  mapped

 

method ToArray: array of T

 

T[] ToArray()

 

func ToArray() -> T...

 

T[] ToArray()

TrueForAll  mapped

 

method TrueForAll(Match: Predicate<T>): Boolean

 

Boolean TrueForAll(Predicate<T> Match)

 

func TrueForAll(_ Match: Predicate<T>) -> Boolean

 

Boolean TrueForAll(Predicate<T> Match)

Parameters:

  • Match:

 

Count

 

property Count: Int32 read;

 

Int32 Count { get; }

 

var Count: Int32 { get{} }

 

Int32 Count { __get; }

Item

 

property Item[i: Int32]: T read write;

 

T Item[Int32 i] { get; set; }

 

subscript Item(_ i: Int32) -> T { get{} set{} }

 

T Item[Int32 i] { __get; __set; }

 

constructor (array of T)

Creates an instance of the class and copies items from the array.

 

constructor(anArray: array of T)

 

List<T>(T[] anArray)

 

init(_ anArray: T...)

 

List<T>(T[] anArray)

Parameters:

  • anArray: Array that stores items which needs to be copied.

constructor (List<T>)

 

constructor(Items: List<T>)

 

List<T>(List<T> Items)

 

init(_ Items: List<T>)

 

List<T>(List<T> Items)

Parameters:

  • Items:

Add  mapped

 

method Add(anItem: T)

 

void Add(T anItem)

 

func Add(_ anItem: T)

 

void Add(T anItem)

Parameters:

  • anItem:

AddRange (array of T)  mapped

 

method AddRange(Items: array of T)

 

void AddRange(T[] Items)

 

func AddRange(_ Items: T...)

 

void AddRange(T[] Items)

Parameters:

  • Items:

AddRange (List<T>)  mapped

 

method AddRange(Items: List<T>)

 

void AddRange(List<T> Items)

 

func AddRange(_ Items: List<T>)

 

void AddRange(List<T> Items)

Parameters:

  • Items:

Clear  mapped

 

method Clear

 

void Clear()

 

func Clear()

 

void Clear()

Contains  mapped

 

method Contains(anItem: T): Boolean

 

Boolean Contains(T anItem)

 

func Contains(_ anItem: T) -> Boolean

 

Boolean Contains(T anItem)

Parameters:

  • anItem:

Exists  mapped

 

method Exists(Match: Predicate<T>): Boolean

 

Boolean Exists(Predicate<T> Match)

 

func Exists(_ Match: Predicate<T>) -> Boolean

 

Boolean Exists(Predicate<T> Match)

Parameters:

  • Match:

Find  mapped

 

method Find(Match: Predicate<T>): T

 

T Find(Predicate<T> Match)

 

func Find(_ Match: Predicate<T>) -> T

 

T Find(Predicate<T> Match)

Parameters:

  • Match:

FindAll  mapped

 

method FindAll(Match: Predicate<T>): List<T>

 

List<T> FindAll(Predicate<T> Match)

 

func FindAll(_ Match: Predicate<T>) -> List<T>

 

List<T> FindAll(Predicate<T> Match)

Parameters:

  • Match:

FindIndex (Predicate<T>): Int32  mapped

 

method FindIndex(Match: Predicate<T>): Int32

 

Int32 FindIndex(Predicate<T> Match)

 

func FindIndex(_ Match: Predicate<T>) -> Int32

 

Int32 FindIndex(Predicate<T> Match)

Parameters:

  • Match:

FindIndex (Int32, Predicate<T>): Int32  mapped

 

method FindIndex(StartIndex: Int32; Match: Predicate<T>): Int32

 

Int32 FindIndex(Int32 StartIndex, Predicate<T> Match)

 

func FindIndex(_ StartIndex: Int32, _ Match: Predicate<T>) -> Int32

 

Int32 FindIndex(Int32 StartIndex, Predicate<T> Match)

Parameters:

  • StartIndex:
  • Match:

FindIndex (Int32, Int32, Predicate<T>): Int32  mapped

 

method FindIndex(StartIndex: Int32; aCount: Int32; Match: Predicate<T>): Int32

 

Int32 FindIndex(Int32 StartIndex, Int32 aCount, Predicate<T> Match)

 

func FindIndex(_ StartIndex: Int32, _ aCount: Int32, _ Match: Predicate<T>) -> Int32

 

Int32 FindIndex(Int32 StartIndex, Int32 aCount, Predicate<T> Match)

Parameters:

  • StartIndex:
  • aCount:
  • Match:

ForEach  mapped

 

method ForEach(Action: Action<T>)

 

void ForEach(Action<T> Action)

 

func ForEach(_ Action: Action<T>)

 

void ForEach(Action<T> Action)

Parameters:

  • Action:

GetItem  mapped

 

method GetItem(Index: Int32): T

 

T GetItem(Int32 Index)

 

func GetItem(_ Index: Int32) -> T

 

T GetItem(Int32 Index)

Parameters:

  • Index:

IndexOf  mapped

 

method IndexOf(anItem: T): Int32

 

Int32 IndexOf(T anItem)

 

func IndexOf(_ anItem: T) -> Int32

 

Int32 IndexOf(T anItem)

Parameters:

  • anItem:

Insert  mapped

 

method Insert(Index: Int32; anItem: T)

 

void Insert(Int32 Index, T anItem)

 

func Insert(_ Index: Int32, _ anItem: T)

 

void Insert(Int32 Index, T anItem)

Parameters:

  • Index:
  • anItem:

InsertRange (Int32, array of T)  mapped

 

method InsertRange(Index: Int32; Items: array of T)

 

void InsertRange(Int32 Index, T[] Items)

 

func InsertRange(_ Index: Int32, _ Items: T...)

 

void InsertRange(Int32 Index, T[] Items)

Parameters:

  • Index:
  • Items:

InsertRange (Int32, List<T>)  mapped

 

method InsertRange(Index: Int32; Items: List<T>)

 

void InsertRange(Int32 Index, List<T> Items)

 

func InsertRange(_ Index: Int32, _ Items: List<T>)

 

void InsertRange(Int32 Index, List<T> Items)

Parameters:

  • Index:
  • Items:

LastIndexOf  mapped

 

method LastIndexOf(anItem: T): Int32

 

Int32 LastIndexOf(T anItem)

 

func LastIndexOf(_ anItem: T) -> Int32

 

Int32 LastIndexOf(T anItem)

Parameters:

  • anItem:

Remove  mapped

 

method Remove(anItem: T): Boolean

 

Boolean Remove(T anItem)

 

func Remove(_ anItem: T) -> Boolean

 

Boolean Remove(T anItem)

Parameters:

  • anItem:

RemoveAt  mapped

 

method RemoveAt(Index: Int32)

 

void RemoveAt(Int32 Index)

 

func RemoveAt(_ Index: Int32)

 

void RemoveAt(Int32 Index)

Parameters:

  • Index:

RemoveRange  mapped

 

method RemoveRange(Index: Int32; aCount: Int32)

 

void RemoveRange(Int32 Index, Int32 aCount)

 

func RemoveRange(_ Index: Int32, _ aCount: Int32)

 

void RemoveRange(Int32 Index, Int32 aCount)

Parameters:

  • Index:
  • aCount:

SetItem  mapped

 

method SetItem(Index: Int32; Value: T)

 

void SetItem(Int32 Index, T Value)

 

func SetItem(_ Index: Int32, _ Value: T)

 

void SetItem(Int32 Index, T Value)

Parameters:

  • Index:
  • Value:

Sort  mapped

 

method Sort(Comparison: Comparison<T>)

 

void Sort(Comparison<T> Comparison)

 

func Sort(_ Comparison: Comparison<T>)

 

void Sort(Comparison<T> Comparison)

Parameters:

  • Comparison:

ToArray  mapped

 

method ToArray: array of T

 

T[] ToArray()

 

func ToArray() -> T...

 

T[] ToArray()

TrueForAll  mapped

 

method TrueForAll(Match: Predicate<T>): Boolean

 

Boolean TrueForAll(Predicate<T> Match)

 

func TrueForAll(_ Match: Predicate<T>) -> Boolean

 

Boolean TrueForAll(Predicate<T> Match)

Parameters:

  • Match: