Duration Types and Sequence Types in JavaFx

Two interesting data types introduced in JavaFX are duration type and sequence type.

Duration Types:

Duration types are used in JavaFX to specify the time duration. The time units can be specified in ms, s, m, or h.  For example:

var timeDuration = 10s;

The variable timeDuration is assigned 10 seconds. The duration type variables can be very useful when animating an object.

Sequence Types:
Sequence types in JavaFX  is a data type that holds a sequence of object values. The interesting thing about sequence types is they can be specified as ranges and also have insert and delete features like that of a list in java.
A simple sequence construction would be:

var numbers = [1,2,3,4,5,6,7,8,9,10];

The same assignment can also be performed as:

var numbers = [1..10];

Keep in mind that the sequence can hold any objects.

var stringsExample = ['this','is','an','example'];

we can also specify datatypes:

var numbers:Number[] = [1..10]

This assignment is the same as the above assignments for numbers variable except in this we specify that the variable numbers carry the Number data type only. Specifying data types are usually useful when sequence of different objects have to be created.
insert expression can be  used with sequence to add an object to the sequence. For example:

insert 11 into numbers;

This statement will add the number 11 to the end of the sequence. So, the range of sequence now is from 1 to 11. We can also specify where we want to add the object.

insert 0 before numbers[0];

This statement adds the number 0 before 1 in the sequence so the range of sequence now is 0 to 10.

insert ['a', 'JavaFx'] after stringExample[2];

This statement adds the sequence [‘a’,’JavaFx’] after ‘an'(index 2 of stringExample) in the sequence stringsExample. so the resulting sequence will be:

stringsExample = ['this', 'is', 'an', 'a', 'JavaFx', 'example']

Similarly delete operation can be performed from a sequence.


delete 'a' from stringsExample;

This statement will delete the value ‘a’ from the sequence stringsExample. If there are multiple ‘a’ in the sequence then all occurrence will be deleted.

delete stringExamples[0..2];

This statement will delete the values in the sequence from index 0 to index 2. So the resulting stringsExample sequence have values [‘a’, ‘JavaFx’, ‘example’];


delete numbers[0];

This statement will delete the value in index 0 of the sequence numbers.

delete numbers;

This statement will delete all the values of the sequence numbers. So, the sequence number is empty sequence after this operation.