One of the reference data types (array)
One, the array
1.1. Definition:
The arrays are of the same data typeMultiple data containers。
1.2. Create format:
Common formats of commonly used arrays
Format 1. Data type [] Array name = {array content 1, array content 2, array content 3...array content n};
public static void main(String[] args) {
// 格式1:数组类型[] 数组名称 = {数据1,数据2,......,数据n};
// 创建数组的同时,并创建数组的内容
int[] student_score1 = {
90, 50, 80, 60, 70, 60 };
}
Format 2. Data type [] Array name = new data type [array length];
public static void main(String[] args) {
// 格式2:数组类型[] 数组名称 = new 数组类型[数组长度];
// 创建数组,并指定长度,不指定数组里面的内容
int[] student_score2 = new int[6];
}
Uncommon array creation format
Format 3. Data type [] array name;
public static void main(String[] args) {
// 格式3:数组类型[] 数组名称;
// 创建数组不初始化
int[] student_score3;
student_score3 = new int[6];//但需要new来初始化
}
Format 4. Data type [] Array name = new data type [] {content 1, content 2, content 3...content n};
public static void main(String[] args) {
// 格式4:数据类型[] 数组名称 = new 数据类型[]{数据1,数据2,......,数据n};
int[] student_score4 = new int[] {
80,70,88,66,99,100};
}
1.3, array length acquisition
Array name.length
public static void main(String[] args) {
// 格式4:数据类型[] 数组名称 = new 数据类型[]{数据1,数据2,......,数据n};
int[] student_score4 = new int[] {
80,70,88,66,99,100};
System.out.println(student_score4 .length);
}
result:
6
to sum up:
Some common creation formats for arrays are summarized here. If you have any questions, please leave a comment.