[Java base Note] Array

Source: Internet
Author: User

Java Basic Notes

To define an array:

int New int // Method One Double New Double [Ten]; int New int [2] [5];

Array created with new, element default value is 0 (0.0)

int // Method Two int // insufficient number of digits, auto-complement 0 {5,3,2,1,6},{10,12,14,15},};

Array attributes: The same type of data is stored, and the length definition is immutable.

Compile will not check the subscript is out of bounds, the execution of the program will produce errors.

Unlike the C language, an array is defined, and the number of elements in an array can be a variable:

int CNT; int New int [CNT];

Array Internal Property Length:

Numbers.length

You can guarantee program extensibility by using the. Length property.

Length,a.length for a two-dimensional array represents his number of rows A[0].length represents the number of columns in row No. 0

Assign the array variable A to the array variable b,a and B to manage the common array space instead of copying all the elements in A to B, which is the same as C.

If you want to copy the contents of a array to the B array, you need to copy the elements one by one, and if you want to determine if all the elements of A and B arrays are equal, you need to judge each element one by one.

Break can jump out of a for loop, and break completely ignores if-else

For-each Cycle:

 for (int k:data) // for each of the elements in the data array, loop through each round, taking the array elements out as a K. { }

[Java base Note] 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.