First Stage 10 array

Source: Internet
Author: User
Tags array length

Array

(a) array:

    An array is a collection of ordered data, and each element in the array has the same array name and subscript to uniquely determine the elements in the array.

   

(ii) One-dimensional array declaration:

     Type [] array;

Type array[];

   Note:

Recommended for use in Java: type [] array;

1. An array is an object

2. Declaring an array does not create an object

3. Do not specify the length when declaring

  

  To create an array:

Create an array of basic data types: int[] i = new int[2];

Create an array of reference data types: student[] s = new student[100];

After an array is created, the elements have an initial value

    

Type default value

BYTE 0

Short 0

int 0

Long 0l

Float 0.0f

Double 0.0d

Char \u0000

Boolean false

Reference types NULL

Initialize the array:

Declaration, creation, initialization separation;

Int[] I; Defining arrays

i = new int[2]; Allocate space

I[0] = 0; Initialization

I[1] = 1;

    

Declare, create, initialize at the same time:

Int[] i = {0,1};//display initialization {} There are several values, the array length is a few

(iii) two-dimensional arrays

Format 1:int[] [] i1 = new Int[2][3];

Defines a two-dimensional array called I1

2 One-dimensional arrays in a two-dimensional array

3 elements in each one-dimensional array

The names of one-dimensional arrays are i1[0],i[1]

Assigning a value of 7 to the first one-dimensional array of 1 feet is i1[0][1]=7;

Format 2:int[] [] i2 = new int[3][];

3 one-dimensional arrays in a two-dimensional array

Each one-dimensional array is a default initialization value of NULL

These three one-dimensional arrays can be initialized individually

I2[0] = new INT[3];

I2[1] = new INT[1];

I2[2] = new INT[2];

Format 3:int[[] arr = {{3,8,2},{2,7},{9,0,1,6}};

Define a two-dimensional array named arr

Three one-dimensional arrays in a two-dimensional array

The specific elements in each one-dimensional array are also initialized

The first one-dimensional array of arr[0]={3,8,2};

The second one-dimensional array of arr[1]={2,7};

The third one-dimensional array arr[2]={9,0,1,6};

The length representation of the third one-dimensional array: arr[2].length;

    

       

First Stage 10 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.