Basic Java Learning 10

Source: Internet
Author: User

Two-dimensional arrays

The array is a reference data type, and the default value is null.

Defines a one-dimensional array in the form of:int[] i = new int[];

It can be seen that each element of a one-dimensional array is an int, then the two-dimensional array is originally each element is now changed to every array, that is, int[].

So the definition of a two-dimensional array is:

int[] [] i = new int [4][5];//red indicates second dimension


The structure of the two-dimensional array in memory:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/74/F3/wKioL1YvPZ3BXjaLAAFH5pOkvxI366.jpg "title=" Qq20151027165715.png "alt=" Wkiol1yvpz3bxjalaafh5pokvxi366.jpg "/>



Exceptions in the array:

1 array subscript out of bounds: java.lang.ArrayIndexOutOfBoundsException

int[] i = new int[3];

for (int m = 0;m <= i.length;m++)

{

System.out.println (I[m]);

}

2 exception for null pointer: java.lang.NullPointerException

(1)

boolean[] i = new boolean[3];

i = null;

System.out.println (I[0]);

(2)

string[] str = new STRING[3];

System.out.println (Str[0]);

(3)

Int[][] J = new int[3][];

J[2][1] = 8;

System.out.println (j[2][1]);


Basic Java Learning 10

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.