Java array memorandum, java Array

Source: Internet
Author: User

Java array memorandum, java Array
Preface

Recently, when I used Java for ACM, I often forgot how to implement static initialization for arrays. So here I will record the common knowledge of Java arrays.

Java array knowledge

An array is an object in Java, and an array instance needs to be created using the new operator.

Common knowledge:

Java array Initialization

Java array initialization includes dynamic initialization and static initialization.

Take an array of the int type as an example to introduce static initialization and dynamic initialization respectively.

Static Initialization
int[] array = new int[] {1, 2, 3, 4, 5, 6};

The code above shows that static Initialization is to display the initial values of each element in the specified array, and the length of the array is determined by the system.

Dynamic Initialization
int[] array = new int[6];

From the code above, we can see that dynamic initialization only specifies the length of the array, and the system assigns the initial value to the array.

For different types, the initial values assigned by the system are also different.

Type Initial Value
Integer type (byte, short, int, long) 0
Floating point type (float, double) 0.0
Character type (char) '\ U000000' (Space)
Boolean) False
Reference Type (class, interface, array) Null

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.