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 use Java array

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use the Java array. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

One-dimensional array 1. Creation method

Array element type array name []

Array element type [] array name

For example:

Int array []; / / int type array String str []; / / String type array

We also need to apply for space for the array:

Array name = new array element type [number of array elements]; array = new int [10]; / / indicates that an integer array with 10 elements has been created / / Note

When we allocate memory for an array with the new keyword, each element in the integer array has an initial value of 0

Combining the above two methods, we can directly open up memory space for the array when declaring it:

Type of array element array name = type of new array element [number of array elements]

Int array [] = new int [10] 2. Initialize array (one-dimensional array)

Common initialization methods are as follows:

Int array [] = new int [] {1 Jing 2 Jing 3 Jing 4 Jing 5}

Or

Int shuzu [] = {1, 2, 3, 4, 5}

Look at a chestnut:

Public class Day {public static void main (String [] args) {int array [] = new int [] {31, 28, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, and int i; for.

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