The method of creating and communicating the array in Java (learning summary) _java

Source: Internet
Author: User

(i) Creation of arrays

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

int score[]=null; Declare one-dimensional array
score=new int[3];//Allocate space with a length of 3

There is another way to declare an array:

Int[] Score=null; Write the brackets in front of the array name

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

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

(ii) Transfer parameters

Because of beginner Java, this is only a discussion of value delivery, regardless of address delivery. There are 3 main points:

· The argument is the array name;

· The parameter is a newly declared array, and if there is a return value, add the bracket "[]" after the type of the function;

· The return value is an array name.

Examples are as follows:

/**
* 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 a small set of Java in the introduction of the array of the creation and communication methods, I hope to help everyone, if you have any questions welcome to my message, small series will promptly reply to everyone!

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.