English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
(1) Array Creation
The creation of an array includes two parts: the declaration of the array and the allocation of memory space.
int score[]=null; //Declare a one-dimensional array score=new int[3}; //allocated with a length of3space
There is another way to declare an array:
int[] score=null; //Write the square brackets in front of the array name
Usually, to make it convenient when writing code, we merge the two lines into one line:
int score[]=new int score[3}; //Write the declaration and memory allocation of the array in one line
(II) Parameter Passing
Since we are beginners in Java, we will only discuss value passing here and not address passing. The main points are3Point:
· The actual parameter is the array name;
· The formal parameter is the newly declared array. If there is a return value, add square brackets "[]" after the function type;
· The return value is the array name.
Example:
/** * Created by lijiaman on 2016/9/16. */ public class createArray2 { public static void main(String[] args) { int score[]=null; score=new int[3}; int speed[]={12,35}; for(int x=0;x<3;x++) { score[x]=x*2+1; } for(int x=0;x<3;x++) { System.out.println("score["+x+"]="+score[x]); } System.out.println("length:");+score.length); for(int x=0;x<speed.length;x++) { System.out.println("Speed:");+speed); } } }
The above is the introduction given by the editor on the creation and parameter passing methods of arrays in Java. I hope it will be helpful to everyone. If you have any questions, please leave a message, and the editor will reply to everyone in time!
Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, does not undergo manual editing, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please replace # with @ when sending an email for reporting, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.