Java one-dimensional array learning

Source: Internet
Author: User


/*
* Java Learning:
* Use of one-dimensional arrays:
Declarative syntax
Datatype[] Name or DataType name[].
Initialization syntax
datatype[] name = new Datatype[length].
datatype[] name = new datatype[] {element1, Element2, ... elementn}.
Datatype[] name = {element1, Element2, ... elementn}.

In Java, you use the keyword new to create an array object in the following format:
Array name = new array element type [number of array elements]
*
*/
public class Test {

public static void Main (string[] args) {
/*
* Function One: Use of similar associative arrays (PHP)
*/
When declaring an array, you cannot specify its length (the number of elements in the array).
String[] subjects=new string[]{"Chinese", "mathematics", "English", "Big things"};
for (String item:subjects) {
SYSTEM.OUT.PRINTLN (item);
}
/*
* Function II: Use of similar indexed arrays
*/
Int[] s;
int i;
s = new Int[5];
for (i = 0; i < 5; i++) {
S[i] = i;
}
for (i = 4; I >= 0; i--) {
System.out.println ("" + s[i]);
}
SYSTEM.OUT.PRINTLN ("Output array-specific index is 3 content: \ t" + s[3]);
}}

Java one-dimensional array learning

Related Article

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.