We are going to learn the array of knowledge in today's group
The first thing to know is what an array
Concept: array:? For storing multiple data types of the same type, the array is a basic type.
? Index: The number of each data in the array. Start numbering from 0 until the array length-1. This data is the same type of data.
Element (array item)?? : One of the data in an index group
Length: The number of elements in the array, and the length is of type int.
Format: data type [] array name =new data type [length];
? For example: int[] array=new int[5];
Meaning to declare a one-dimensional array of length 5 array? After declaring an array, the system defaults to the default type for the data.
Number type: Default is 0 0.0
Boolean type: Default is False
Char type: Default is ' + '?
String type: default is? null
Other notation int array[]=new int[5];
Assignment array[0]=1;?
array[1]=2;? ?
array[2]=5;?
array[3]=2;?
array[4]=11;?
int [] Array=new int[]{1,2,3,5,6};? Assign values directly in parentheses.
? ? The traversal of an array
First method: For loop traversal
for (int i=0;i
System.out.println (Array[i]);
}?
? second method: Foreach Loop traversal
foreach Loop: Takes each array item in the array sequentially, extracts it once, assigns the array to the variable, executes the loop body, and then removes an assignment to the variable until all the array items in the array have been exhausted.
for (data type; variable name; array name) {
Loop Body Statement
}?
for (int item;array) {
SYSTEM.OUT.PRINTLN (item);
}?
The Foreach loop cannot change the subscript (index), also called a read-only loop. The advantage is that when iterating through a collection, it is much more efficient than a for loop. Collection We'll talk about it in the next place, which is not covered now.
How do you copy an array into another array
Int[] Array1=new int[]{3,2,5,6,7}?;
Int[] Array2=new int[array1.length];
for (int i=0;i
? {Array2[i]=array1[i];
}?
Well, today's array learning ends here, thank you for watching.?
Java Fundamentals 05