The sequence can also be created as below:
var numbers = [10,20,30,40];
var names = [“Java”, “FX”];
Sequences are not objects but the ordered list of objects. If their length and elements are equal
then they are considered to be equal.
For example, the code:
var myArray:Integer[];
myArray =[10,20];
java.lang.System.out.println(“Equal? “+ {myArray == [10,20]});
Gives output as below:
Equal? true
It has one interesting feature: It provides a short notation ‘..’ for sequences in arithmetic series.
For example, the code below:
var values = [1..50]; // No need to type all numbers from 1 to 50.
java.lang.System.out.println(“values[0]: “+ values[0]);
java.lang.System.out.println(“values[1]: “+ values[1]);
java.lang.System.out.println(“values[2]: “+ values[2]);
java.lang.System.out.println(“values[49]: “+ values[49]);
Gives output as below:
values[0]: 1
values[1]: 2
values[2]: 3
values[49]: 50
Inserting an element into a sequence:
Syntax for inserting a new element in the sequence is like below:
insert n into mySequence;
insert n before mySequence [index];
insert n after mySequence [index];
For example, the code below:
var mySequence = [1..5];
insert 7 into mySequence;
insert 6 before mySequence [5]; |