Summary of array knowledge in Java

Source: Internet
Author: User

This week we learned the basic concepts of arrays, including one-dimensional arrays, two-dimensional arrays, and even multidimensional arrays. Here, I make a simple summary of the basic knowledge points of the array, in order to later temperature.

First, the basic concepts and syntax of the array:

An array is a one-time definition of multiple variables, which is a collection of elements of the same data type; basic syntax:

1. Declaration of an array: Two ways to declare an array: (1) data type [] array name for example: int [] A; (2) data type array name [] For example: int a [];

2. Length of the array: Array.Length.
int [] array = new int []{1,2,3,4,5,6,7};
System.out.println (Array.Length); When creating an array, you must specify the length of the array, and no change is allowed once defined.
3. The subscript of the array: 0--array.length-1; The maximum subscript is the length length-1;

4. Three major features of the array (cons):

(1) The memory space created by the array can only store data of the same data type;

(2) The memory space allocated by the array is continuous;

(3) The allocated memory space of an array is not extensible; that is, the length of the array cannot be changed once it is determined;

5. Array stores the values of the data:

The creation of an array must first be initialized, local variables: used after first assignment; array elements: uninitialized, with default values.

The default value for an array of type int is: 0
The default value for an array of type Boolean is: false
The default value for an array of type Byte is: 0
The default value for array of type short is: 0
The default value for an array of type float is: 0.0
The default value for an array of type Double is: 0.0

The initial value of an array of type string is: null

6. Expansion of arrays: int [] a = new int[3];

A) Create a new array int [] b = new Int[6];

b) Copy the data from the old array to the new array a---->b (copy)

(c) Let the old array point to the new array's address A = B;

7. Two-dimensional array:

For example: int[][] a = new int [2][3]; Low dimension control Row (outer) High dimension Control column (inner layer). A two-dimensional array is a one-dimensional array of one-dimensional arrays: int [] [] a = new int[2][3];

Length of two-dimensional array: a.length------outer array (row); b.length------> Inner Array (column)

Summary of array knowledge in Java

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: 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.