Methods of creating and passing parameters of arrays in Java (learning summary)

(1) Array creation

The creation of array includes two parts: the declaration of array and the allocation of memory space.

There is another way to declare arrays:

int[] score=null; // Write brackets before the array name

Usually, when writing code, we combine two lines into one line for convenience:

int score[]=new int score[3]; // Write the array declaration and allocated memory on one line

(2) Transfer parameters

As a beginner of Java, only value passing is discussed here, and address passing is not considered. There are three main points:

・ the argument is the array name;

・ the formal parameter is a newly declared array. If there is a return value, square brackets "[]" shall be added after the type of the function;

・ the return value is the array name.

Examples are as follows:

The above is the method of creating and transmitting arrays in Java introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>