/*
* 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