How to Create Array in Roku

Posted By : Prashant Grover | 09-Jan-2017

Array in Roku

As we all know that arrays are basicaally those data structurewhich are capable of storing a fixe sized collection of sequential elements of the same type, but in roku array are used to store indexed collection of brightscript objects. Bright script array are different from other languages because here they can be of different types or may be all of the same type and can vary in size.

 

  • How to create an array in Roku

 

  The syntax of creating roArray is : CreateObject("roArray",size As Integer,resize as Boolean).

 

  a. Here in the above syntax, size is the initial number of elements allocated to array.

 

  b. If resize is true, the array size will automatically increase if there are more elements, but if array is large this   can be slow.

 

Example :    stringArray=createObject("roArray", 3, true)

                    stringArray.Push("this")

                    stringArray.Push("is an")

                    stringArray.Push("roArray")

 

Methods supported by roArray in roku are :

 

1. Peek() As Dynamic - its return type is dynamic i.e it has generic return type, this method is used to fetch the last entry from the array without removing it from array, if the array does not contain any element then in this case it returns invalid

 

2. Pop() As Dynamic - its return type is dynamic i.e it has generic return type, this method is used to fetch the last entry from the array and it removes it from array, if the array does not contain any element then in this case it returns invalid and does not change the array.

 

3. Shift() As Dynamic - its return type is dynamic i.e it has generic return type, this method is used to remove the top/first entry from the array and shifts all the elements down by one to fill the empty space. This method return the removed entry i.e the the first array element. This is like pop from the start of the array instead from the end.

 

4. Unshift(tValue as Dynamic) As Void - This method is used to insert an element at the top in array, it is like push to the start of the array instead of last.

 

5. Push(tValue as Dynamic) As Void - this method is used to add an element into an array at the last position i.e at the end.

 

6. Count() As Integer - this method is used to get the length of an array i.e one more than the index of highest entry, the return type of this method is Integer.

 

7. Clear() As Void - this method is used to delete every entry from an array.

 

About Author

Author Image
Prashant Grover

Prashant is a bright Java developer, his area of expertise are Core Java, Android , Spring . Grails etc. Apart from that he spends his time playing volleyball.

Request for Proposal

Name is required

Comment is required

Sending message..