Queue<T>

Overview

Represents a first-in, first-out (FIFO) collection of objects.

Queue allows access only to first element of the collection. Queue accepts nil as a valid value for reference types and allows duplicate elements.

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

Use case

You can use Queue<T> class when you need to create a FIFO queue:

var Numbers := new Queue<Integer>;
Numbers.Enqueue(1);
Numbers.Enqueue(2);
Numbers.Enqueue(3);
Numbers.Enqueue(4);

writeLn(Sugar.String.Format("Current: {0}", Numbers.Dequeue));
writeLn(Sugar.String.Format("Next in queue: {0}", Numbers.Peek));  

while Numbers.Count > 0 do
  writeLn(Sugar.String.Format("Current: {0}", Numbers.Dequeue));

Output:

Current: 1
Next in queue: 2
Current: 2
Current: 3
Current: 4

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

 

Clear  mapped

 

method Clear

 

void Clear()

 

func Clear()

 

void Clear()

 

Sub Clear()

Contains  mapped

 

method Contains(Item: T): Boolean

 

Boolean Contains(T Item)

 

func Contains(_ Item: T) -> Boolean

 

Boolean Contains(T Item)

 

Function Contains(Item As T) As Boolean

Parameters:

  • Item:

Count

 

property Count: Int32 read;

 

Int32 Count { get; }

 

var Count: Int32 { get{} }

 

Int32 Count { __get; }

 

ReadOnly Property Count() As Int32

Dequeue  mapped

 

method Dequeue: T

 

T Dequeue()

 

func Dequeue() -> T

 

T Dequeue()

 

Function Dequeue() As T

Enqueue  mapped

 

method Enqueue(Item: T)

 

void Enqueue(T Item)

 

func Enqueue(_ Item: T)

 

void Enqueue(T Item)

 

Sub Enqueue(Item As T)

Parameters:

  • Item:

Peek  mapped

 

method Peek: T

 

T Peek()

 

func Peek() -> T

 

T Peek()

 

Function Peek() As T

ToArray  mapped

 

method ToArray: array of T

 

T[] ToArray()

 

func ToArray() -> T...

 

T[] ToArray()

 

Function ToArray() As T()

 

Count

 

property Count: Int32 read;

 

Int32 Count { get; }

 

var Count: Int32 { get{} }

 

Int32 Count { __get; }

 

ReadOnly Property Count() As Int32

 

Clear  mapped

 

method Clear

 

void Clear()

 

func Clear()

 

void Clear()

 

Sub Clear()

Contains  mapped

 

method Contains(Item: T): Boolean

 

Boolean Contains(T Item)

 

func Contains(_ Item: T) -> Boolean

 

Boolean Contains(T Item)

 

Function Contains(Item As T) As Boolean

Parameters:

  • Item:

Dequeue  mapped

 

method Dequeue: T

 

T Dequeue()

 

func Dequeue() -> T

 

T Dequeue()

 

Function Dequeue() As T

Enqueue  mapped

 

method Enqueue(Item: T)

 

void Enqueue(T Item)

 

func Enqueue(_ Item: T)

 

void Enqueue(T Item)

 

Sub Enqueue(Item As T)

Parameters:

  • Item:

Peek  mapped

 

method Peek: T

 

T Peek()

 

func Peek() -> T

 

T Peek()

 

Function Peek() As T

ToArray  mapped

 

method ToArray: array of T

 

T[] ToArray()

 

func ToArray() -> T...

 

T[] ToArray()

 

Function ToArray() As T()