Java Reference
In-Depth Information
It is critical to understand that sequences are immutable, meaning that the
values in a sequence do not change. Rather, any modification to a sequence
(insert, delete, and so on) generates a new sequence object to reflect the
modification desired.
When deleting by value (that is, delete "May" from months ), all items
of same value will be removed from the sequence.
Sequence slices
Sequence slice notations are used to generate subsets of larger sequences. Given
this sequence
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"];
Here are some slice operations supported by JavaFX:
F months[1..4] —returns a sequence ["Feb", "Mar", "Apr", "May"]
F months[0..<3] —returns sequence [ "Jan", "Feb", "Mar"]
F months[3..] —returns sequence ["Apr", "May", "Jun"]
F months[0..<] —returns sequence ["Jan", "Feb", "Mar", "Apr", "May"]
Sequence-Projection—you can use constraint expressions to project sub-sequences on a
given sequence using format sequence[x | {Boolean expression}] . This notation
reads as "select all element x where the Boolean expression is true".
:
months[m|m.startsWith("M")]
The above code returns sequence ["Mar", "May"] from var months declared previously.
This expression creates slices based on given arbitrary Boolean condition. It reads as "for all
item m in months where m starts with M ."
Sequence loop query
The loop structure is used to query elements in sequences to create subsets based on
conditional expressions. The general format is:
for (x0 in seq0 [where {Boolean expression}][, queryn]){}
The loop expression can use a where clause along with a Boolean expression to filter down
to specific elements to build the subset. A simple example is:
var points = [1,2,3,4,5,6,7,8,9,10,11,12,13,14];
var evenPoints = for(n in points where n mod 2 == 0) {n}
println (evenPoints);

Search WWH ::

Custom Search