Introduction to Java Syntax (iv): array

Source: Internet
Author: User
Tags arrays

1: Array Description

Arrays are special types in the Java language. They store a series of objects that can be referenced by index, and you can define arrays of arrays, and here are some examples:

int i[];

Char c[];

float f[][];

2: Array operators

In Java, an array is allocated by using the new operator to create an array and then assign it to a variable, such as:

int i[]=new int[10];

The previous example creates an array of 10 integer variables and assigns it to I, and you will get the variable i[0],i[1],......,i[8],i[9 in numerical order, noting that the subscript starts with 0 of the first element and the number of the array minus 1.

The use of an array is the same as a variable, and each member of the array can be used where the same variable is used, and Java also supports multidimensional arrays.

Char C[][]=new char[10][10];

float f[][]=new float[5][];

Note In the second note only one-dimensional dimensions are determined, and Java requires that at least one dimension of the scale is determined at compile time (i.e. in the source code), and the dimensions of the remainder can be allocated later.

Arrays are used primarily for the fact that you have a large number of related data that you want to store together and that you can simply access them by numbers, which is very powerful.

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.