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<T> 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)

 

Sub New(anArray As T())

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)

 

Sub New(Items As List<T>)

Parameters:

  • Items:

Add  mapped

 

method Add(anItem: T)

 

void Add(T anItem)

 

func Add(_ anItem: T)

 

void Add(T anItem)

 

Sub Add(anItem As T)

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)

 

Sub AddRange(Items As T())

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)

 

Sub AddRange(Items As List<T>)

Parameters:

  • Items:

Clear  mapped

 

method Clear

 

void Clear()

 

func Clear()

 

void Clear()

 

Sub Clear()

Contains  mapped

 

method Contains(anItem: T): Boolean

 

Boolean Contains(T anItem)

 

func Contains(_ anItem: T) -> Boolean

 

Boolean Contains(T anItem)

 

Function Contains(anItem As T) As Boolean

Parameters:

  • anItem:

Count

 

property Count: Int32 read;

 

Int32 Count { get; }

 

var Count: Int32 { get{} }

 

Int32 Count { __get; }

 

ReadOnly Property Count() As Int32

Exists  mapped

 

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

 

Boolean Exists(Predicate<T> Match)

 

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

 

Boolean Exists(Predicate<T> Match)

 

Function Exists(Match As Predicate<T>) As Boolean

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)

 

Function Find(Match As Predicate<T>) As T

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)

 

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

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)

 

Function FindIndex(Match As Predicate<T>) As Int32

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)

 

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

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)

 

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

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)

 

Sub ForEach(Action As Action<T>)

Parameters:

  • Action:

GetItem  mapped

 

method GetItem(Index: Int32): T

 

T GetItem(Int32 Index)

 

func GetItem(_ Index: Int32) -> T

 

T GetItem(Int32 Index)

 

Function GetItem(Index As Int32) As T

Parameters:

  • Index:

IndexOf  mapped

 

method IndexOf(anItem: T): Int32

 

Int32 IndexOf(T anItem)

 

func IndexOf(_ anItem: T) -> Int32

 

Int32 IndexOf(T anItem)

 

Function IndexOf(anItem As T) As Int32

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)

 

Sub Insert(Index As Int32, anItem As T)

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)

 

Sub InsertRange(Index As Int32, Items As T())

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)

 

Sub InsertRange(Index As Int32, Items As List<T>)

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; }

 

Property Item(i As Int32) As T

LastIndexOf  mapped

 

method LastIndexOf(anItem: T): Int32

 

Int32 LastIndexOf(T anItem)

 

func LastIndexOf(_ anItem: T) -> Int32

 

Int32 LastIndexOf(T anItem)

 

Function LastIndexOf(anItem As T) As Int32

Parameters:

  • anItem:

Remove  mapped

 

method Remove(anItem: T): Boolean

 

Boolean Remove(T anItem)

 

func Remove(_ anItem: T) -> Boolean

 

Boolean Remove(T anItem)

 

Function Remove(anItem As T) As Boolean

Parameters:

  • anItem:

RemoveAt  mapped

 

method RemoveAt(Index: Int32)

 

void RemoveAt(Int32 Index)

 

func RemoveAt(_ Index: Int32)

 

void RemoveAt(Int32 Index)

 

Sub RemoveAt(Index As Int32)

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)

 

Sub RemoveRange(Index As Int32, aCount As Int32)

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)

 

Sub SetItem(Index As Int32, Value As T)

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)

 

Sub Sort(Comparison As Comparison<T>)

Parameters:

  • Comparison:

ToArray  mapped

 

method ToArray: array of T

 

T[] ToArray()

 

func ToArray() -> T...

 

T[] ToArray()

 

Function ToArray() As T()

TrueForAll  mapped

 

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

 

Boolean TrueForAll(Predicate<T> Match)

 

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

 

Boolean TrueForAll(Predicate<T> Match)

 

Function TrueForAll(Match As Predicate<T>) As Boolean

Parameters:

  • Match:

 

Count

 

property Count: Int32 read;

 

Int32 Count { get; }

 

var Count: Int32 { get{} }

 

Int32 Count { __get; }

 

ReadOnly Property Count() As Int32

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; }

 

Property Item(i As Int32) As T

 

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)

 

Sub New(anArray As T())

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)

 

Sub New(Items As List<T>)

Parameters:

  • Items:

Add  mapped

 

method Add(anItem: T)

 

void Add(T anItem)

 

func Add(_ anItem: T)

 

void Add(T anItem)

 

Sub Add(anItem As T)

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)

 

Sub AddRange(Items As T())

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)

 

Sub AddRange(Items As List<T>)

Parameters:

  • Items:

Clear  mapped

 

method Clear

 

void Clear()

 

func Clear()

 

void Clear()

 

Sub Clear()

Contains  mapped

 

method Contains(anItem: T): Boolean

 

Boolean Contains(T anItem)

 

func Contains(_ anItem: T) -> Boolean

 

Boolean Contains(T anItem)

 

Function Contains(anItem As T) As Boolean

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)

 

Function Exists(Match As Predicate<T>) As Boolean

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)

 

Function Find(Match As Predicate<T>) As T

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)

 

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

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)

 

Function FindIndex(Match As Predicate<T>) As Int32

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)

 

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

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)

 

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

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)

 

Sub ForEach(Action As Action<T>)

Parameters:

  • Action:

GetItem  mapped

 

method GetItem(Index: Int32): T

 

T GetItem(Int32 Index)

 

func GetItem(_ Index: Int32) -> T

 

T GetItem(Int32 Index)

 

Function GetItem(Index As Int32) As T

Parameters:

  • Index:

IndexOf  mapped

 

method IndexOf(anItem: T): Int32

 

Int32 IndexOf(T anItem)

 

func IndexOf(_ anItem: T) -> Int32

 

Int32 IndexOf(T anItem)

 

Function IndexOf(anItem As T) As Int32

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)

 

Sub Insert(Index As Int32, anItem As T)

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)

 

Sub InsertRange(Index As Int32, Items As T())

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)

 

Sub InsertRange(Index As Int32, Items As List<T>)

Parameters:

  • Index:
  • Items:

LastIndexOf  mapped

 

method LastIndexOf(anItem: T): Int32

 

Int32 LastIndexOf(T anItem)

 

func LastIndexOf(_ anItem: T) -> Int32

 

Int32 LastIndexOf(T anItem)

 

Function LastIndexOf(anItem As T) As Int32

Parameters:

  • anItem:

Remove  mapped

 

method Remove(anItem: T): Boolean

 

Boolean Remove(T anItem)

 

func Remove(_ anItem: T) -> Boolean

 

Boolean Remove(T anItem)

 

Function Remove(anItem As T) As Boolean

Parameters:

  • anItem:

RemoveAt  mapped

 

method RemoveAt(Index: Int32)

 

void RemoveAt(Int32 Index)

 

func RemoveAt(_ Index: Int32)

 

void RemoveAt(Int32 Index)

 

Sub RemoveAt(Index As Int32)

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)

 

Sub RemoveRange(Index As Int32, aCount As Int32)

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)

 

Sub SetItem(Index As Int32, Value As T)

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)

 

Sub Sort(Comparison As Comparison<T>)

Parameters:

  • Comparison:

ToArray  mapped

 

method ToArray: array of T

 

T[] ToArray()

 

func ToArray() -> T...

 

T[] ToArray()

 

Function ToArray() As T()

TrueForAll  mapped

 

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

 

Boolean TrueForAll(Predicate<T> Match)

 

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

 

Boolean TrueForAll(Predicate<T> Match)

 

Function TrueForAll(Match As Predicate<T>) As Boolean

Parameters:

  • Match: