Array-related knowledge points

Source: Internet
Author: User

      

Concept:
An array can be called a collection of multiple identical types of data, and the unified management of these data
The variable of an array is a reference type, and an array is itself an object, and each element in the array is equal to the member variable of that object
The elements of an array can be any data type, including basic data types and reference types

How to declare:
Type [] Variable name = new Type [length]
Or
Type variable name [] = new Type [length]
Int[] A;
Double[] D;
String[] s;
Person[] p;

To use the New keyword when declaring an array,
1, the length of the array must be declared, int[] a = new int[5];
2, you can also directly define the contents of the array int[] A = {1, 2, 3}
3, once the length of the array is defined, it cannot be changed

Traversal and initialization (for the and of int arrays)
Static initialization/Dynamic initialization
Base type
Reference type
Initialization and definition of a two-dimensional array: int[][] AA = new int[3][];

The object of the array will have a property called length, to record the lengths
Accesses an element in an array, using an index
Index starting from 0
Int[] A = {1,2,3,4,5};
A[2]
An array of strings in the Main method (analog calculator)

Array-related knowledge points

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.