JavaFX (III.) array

Source: Internet
Author: User
Tags arrays

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.