Using Java one-dimensional arrays and multidimensional arrays

Source: Internet
Author: User

Array, which is a combination of multiple data types of the same type.

The use of arrays includes declaring arrays, creating arrays, assigning values.

Declaration of one-dimensional array, such as: float[] A; or float a[]

Declarations of two-dimensional arrays, such as: float[] [] A or float a[[]

The array declaration is not yet available, and it is created to assign an address entry to a.

One-dimensional array creation, such as A=new Float[4]

Two-dimensional array creation, such as A=new Float[3][4]

Of course, declarations and creation can be expressed in one sentence: float a[]=new float[4] float a[][]=new float[3][4]

Note: In particular, for multidimensional arrays, such as float a[][]=new float[3][] This sentence only creates one dimension, two dimensions have not yet been created, and add:

A[0]=new float[5];a[1]=new float[4];a[2]=new float[12];

After an array is created, the general environment assigns an initial value to the array variable, such as:

a[0]=12.3f;a[1]=34.23f;

More simply, we can implement the Declaration, creation, and assignment in just one sentence, such as:

Float a[]={21.23f, 34.12f, 56.37f}

float a[] []={{12.23f, 45.67f, 10.98f},{23.34f,22.22f}}

The above is a personal learning harvest, if there are errors, please correct me.

Using Java one-dimensional arrays and multidimensional arrays

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.