Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize dynamic initialization of Java array

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to achieve dynamic initialization of Java array". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to realize dynamic initialization of Java array".

Concept

1. Array dynamic initialization only gives the array length, and the system initializes the value by default.

2. Format

Data type [] array name = new data type [array length]; int [] arr = new int [3]

Example

Dynamic initialization of package com.itheima.array; public class Demo2Array {/ * array: during initialization, you need to specify the length of the array manually, and the system will assign the initial value to the array container. Dynamic initialization format: data type [] array name = new data type [length of array] Note: when printing array variables The memory address of the array will be printed out [I@10f87f48: @: delimiter]: the current space is an array type I: the data type stored in the current array container 10f87f48: in hexadecimal Storage address 0 1 2 3 4 5 6 7 8 9 a b c d e f * / public static void main (String [] args) {/ / data type [] array name = new data type [length of array] / / create an array container of type int through the new keyword, which can store five integers of type int. The container is recorded by the arr array variable int [] arr = new int [5]; / / [I@10f87f48 System.out.println (arr); byte [] bArr = new byte [3] / / [B@b4c966a System.out.println (bArr);}} Thank you for reading. The above is the content of "how to realize dynamic initialization of Java array". After the study of this article, I believe you have a deeper understanding of how to achieve dynamic initialization of Java array, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report