Java Reference
In-Depth Information
Let's use the students sequence from the previous example:
students[3] = "john";
The assignment to position 3 would be ignored because the size of students is cur-
rently 3, and the highest valid index is 2. Similarly, assignment to the index -1 is
silently ignored for the same reason; -1 is outside of the sequence range.
Furthermore, if you access an element location outside of the existing range for the
sequence, a default value is returned. For
Number
s, this is zero; for
Strings
, the
empty string; for
Object
s, this is null.
To insert an element into the sequence, use the
insert
statement:
// add "vijay" to the end of students
insert "vijay" into students;
// insert "mike" at the front of students
insert "mike" before students[0];
// insert "george" after the second student
insert "george" after students[1];
To delete an element, use the
delete
statement:
delete students[0];
// remove the first student
delete students[0..1];
// remove the first 2 students
delete students[0..<2];
// remove the first 2 students
delete students[1..];
// remove all but the first student
delete "vijay" from students;
delete students;
// remove all students
Native array is a feature that allows you to create Java arrays. This feature is
mainly used to handle the transfer of arrays back and forth from JavaFX and
Java. An example of creating a Java
int[]
array is shown in the following code.
var ints: nativearray of Integer =
[1,2,3] as nativearray of Integer;
Native arrays are not the same as sequences, though they appear similar. You can-
not use the sequence operators, such as
insert
and
delete
, or slices
.
However, you
can do assignments to the elements of the array as shown in the following code:
ints[2] = 4;
Search WWH ::
Custom Search