Crazy java--Fourth chapter flow control and array

Source: Internet
Author: User

4.5 Array type

An array is also a type. It is itself a reference type. For example, int is a basic type, int[] is a reference type.

Two ways to define an array:

1.type[] Arrayname;

2.type arrayname[];

The first one is usually recommended, which is both easy to understand and conforms to the syntax for defining variables.

If the index value specified when accessing an array element is less than 0, or greater than or equal to the length of the array, the compiler will not have any errors, but the runtime throws an exception

4.5.5foreach Cycle

String[] books={"Kingdoms", "Journey to the Monkey", "Red Mansions"}; for (String book:books) {    System.out.println (book);}

But one thing, when using foreach to iterate over an algebraic group element, the loop variable in foreach is equivalent to a temporary variable, and the system assigns the array element to the temporary variable at once, which is not an array element, it only holds the value of the array element, so if you want to change the value of the array element, You cannot use the Foreach loop.

4.6 In-depth arrays

Crazy java--Fourth chapter flow control and array

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.