Beginner Java Fourth day

Source: Internet
Author: User

Array:

1, the Declaration of the array of two ways:

data type [] array name for example: int [] A;

The name of the array of data types [] For example: int a [];

2, array creation of three ways:

Allocates memory based on the specified length while declaring an array, but the element values in the array are the default initialization values

char[] Chary = new CHAR[10];

Declares an array and allocates memory, with its initial value

int[] Ary1 = new Int[]{1, 2, 3, 4, 5};

The same way as the previous one, just a relatively brief syntax

Int[] Ary2 = {1, 2, 3, 4, 5};

3, the length of the group: Long property

int [] B1 = new int []{1,2,3,4,5,6,7}; System.out.println (b1.length);

Note: The length of the array is an attribute, and the length of the string is long ();

When creating an array, you must specify the length of the array, and no change is allowed once defined. The length of the array, although 7, is actually given in memory to 8 positions, from 0-7.

4, two-dimensional array definition: Multidimensional array is an array of arrays, that is, the elements of the array is also an array

For example: int [][]a = {{1},{1,2},{1,2,3}};

Declaration of two-dimensional arrays: three ways:

int [] [] A; int []a1[]; int a2[][];

Note: The first type of data that is not easily confused with a is recommended

Beginner Java Fourth day

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.