Java Basic Road (i)--array of reference data types

Source: Internet
Author: User
Tags array length

The last time we talked about Java's underlying data type, let's talk about the array in the reference data type today.

What is an array

Array: An element collection of the same data type (reference data type) stored in a contiguous block of memory.

Each of the data in the array is called an array element, and the elements in the array are indexed to indicate where they are stored, and the Index (subscript) starts at 0.

Definition of an array

First way: type [] array name ; as int[] nums;
The second way: type array name []; as int nums[];
Most Java programmers prefer to use the first style because it separates the data type int[] from the variable name Num.

Initialization of the array

Arrays in Java must be initialized before they can be used .
Initialization is the allocation of memory to an array element, and the initial value is assigned to each element.

initialize the array in two ways:
Span style= "Font-family:tahoma, Arial, Helvetica, Sans-serif;" > - static initialization :
syntax format : type [] array name =new array type []{element 1, Element 2, Element 3,... Element n};
simplified syntax: type [] Array name = {element 1, element 2, Element 3 ... Element n};
- dynamic initialization :
If we don't know what data is stored in the array beforehand, You can use dynamic initialization when you only know how many data you need to store.
dynamic initialization: The length of the array specified by us when initializing, The system automatically assigns an initial value to an array element.
format: type [] array name =new array type [array length];

Note : regardless, in which way the array is initialized, once the initialization is complete, the length of the array is fixed and cannot be changed unless reinitialized. In other words, the array is fixed length.

Today, when it comes to personal opinion, if there are deficiencies, please forgive me.

Java Basic Road (i)--array of reference data types

Related Article

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.