In the JavaFX actually does not have the traditional meaning the array, the correct name should be the sequence, namely sequence, it resembles the traditional language storehouse inside ArrayList, does not have the length limit, may add the element or deletes the element at any time, but also provides some additional operations.
1. Define an array
Place the elements in square brackets and separate them with commas to define them.
VarweekDays = ["Mon","Tue","Wed","Thur","Fri"];
2. Automatic flattening of arrays
var days = [weekdays, ["Sat", "Sun"]];
The days here are automatically expanded to ["Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun"];
3, create equal margin group
var nums = [1……100];var nums2 = [1……100 step 2];
Step 2 What do you mean, it's not going to be easy? Oh. Note: The difference here is that the value of the element is linear, and the number of the elements is also incremented from the beginning of the 0 order.
4, array of arrays
var weekDays = ["Mon","Tue","Wed","Thur","Fri"];
var days = [weekDays, weekDays];
System.out.println(days[1]);
Result: May not be the same as you think, not weekdays, but Tue
5. Referencing an element in an array
var nums = [1……5];
System.out.println(nums[3]);
The output should be: 4
6. Insert an element into the array
First case: Default, insert to Last
var nums = [1……5];insert 0 into nums;
System.out.println(nums);
Results: [1, 2, 3, 4, 5, 0]
0 is plugged into the final position.
Second scenario: Before inserting to the specified item
var nums = [1……5];
insert 0 before nums[3];
System.out.println(nums);
Change into before and specify the reference position.
Results: [1, 2, 3, 0, 4, 5]
Third scenario: After inserting the specified item
var nums = [1……5];
insert 0 after nums[3];
System.out.println(nums);
Just change the before to after.
Results: [1, 2, 3, 4, 0, 5]