Java Reference
In-Depth Information
To get the current size of a sequence use the sizeof operator.
var numEvenNumbers = sizeof evenNumbers;
Accessing Sequence Elements
To access an individual element, use the numeric index of the element within
square brackets:
var firstMonth = monthNames[0];
You can also take slices of sequence by providing a range. Both of the next two
sequences are equal.
var firstQuarter = monthNames[0..2];
var firstQuarter = monthNames[0..<3];
The following two sequences are also equal. The second example uses a syntax
for range to indicate start at an index and return all elements after that index.
var fourthQuarter = monthNames[9..11 ];
var fourthQuarter = monthNames[9.. ];
To iterate over a sequence, use the for loop:
for( month in monthNames) {
println("{month}");
}
Modifying Sequences
To replace an element in a sequence, just assign a new value to that indexed loca-
tion in the index.
var students = [ "joe", "sally", "jim"];
students[0] = "vijay";
Developer Note: As we said at the beginning of this chapter, JavaFX is a forgiv-
ing language, so if you assign to an element index location outside of the existing
size of the sequence, the assignment is silently ignored.
 
 
Search WWH ::




Custom Search