S1/using Java to understand program logic/08-Arrays

Source: Internet
Author: User

Steps to use the array:

(1) declaring an array

Declaring a one-dimensional array in Java

The syntax is as follows:

Array type [] array name;

Or

Array type array name [];

(2) Allocating space

The syntax is as follows:

Array name =new data type [array length];

You can combine the declaration array, the allocation space,

The syntax is as follows:

data type [] array name =new data type [array length];

(3) Assign value

The syntax is as follows:

Array name [subscript value];

The declaration array, allocation space, and assignment can be combined to complete

The syntax is as follows:

data type [] Array name ={value 1, value 2, value 3, value 4, value 5,......, value N,};

Note: Creating and assigning values directly is generally used in cases where the array element is less. He must complete it, and the following code is not legal:

Int[] score;

SCORE={60,70,98,90,76}; Error

(4) Processing of data

array element Initial value

Data type

Initial value

Int

0

Double

0.0

Char

' \u0000 '

Bollean

False

Array sort, Syntax:

Arrays.sort (array name);

Arrays is a class provided in Java, and sort () is a method of the class. By the syntax above, the array name is placed in parentheses of the sort () method, and the array can be sorted. Therefore, after this method executes, the elements in the array are ordered (ascending).

The contents of the output array, syntax:

Arrays.tostring (array name);

S1/using Java to understand program logic/08-Arrays

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.