Java Beginner: Array, get array length

Source: Internet
Author: User

Getting the length of the array in Java is simple: the array name. Length, let's see a simple program on it, as follows:

This is the last time that the program, I just changed for the back of the 4 into a a.length, perhaps someone asked, then why do not require the length of the group? When the array starts, is the length determined? Yes, but sometimes it happens that we don't know the length of the array, for example, when a function parameter is an array (we'll talk about the function later), for example, if the length of the array is entered by the user? Now let's do a program that lets the user enter an integer data as the length of the array, and then create an array of that length, randomly assigning values to the elements inside, and finally printing the array, and the program is as follows:

Of course, some people may say, since we have got the size in the program, then simply use size, it is not necessary to use length it? Well, I can only tell you that this is true for this program. However, the size can be changed, it does not always represent the current length of the array, but the length is definitely the size of this array. In addition, for (int element:array) ..., here is the For Each loop, which belongs to the for loop category, but we did not say that because the For Each loop involves an array, we have to say the array before we can say the For Each loop.

Okay, I'm going to be here today, I got a headache, I'll go get some sleep.

Java Beginner: Array, get array length

Related Article

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.