Learning about arrays
1. Define an array: int [] list = new int[];
2. When passing an array object to a method, the method can directly modify the contents of the array without having to be implemented by a return value.
Cases:
1 Public Static void incrementall (int[]data) {2for (int i = 0;i< list.length;i++) {3 data[i]++; 4 }5 }
You can call Incrementall (list) directly;
If you define an array inside a method note (1) There is a return value (2) that does not require an array parameter
1 PublicStsticint[] Buildingarray (intsize) {2 int[]data =New int[size];3 for(inti = 0;i<data.length;i++){4Data[i] = 2*i+1;5 }6 returndata; 7}
3. Note that the first limitation of the *1* array is that it cannot change its size at run time.
*2* cannot print array contents with a simple print or println method,
*3* cannot use simple = = to compare whether an array is equal.
Method: Arrays.copyof (array,newsize) returns a specified copy with the content set to a value;
Arrays.copyofrange (Array,startindex,endindex) returns a partial copy of the value from the specified array index from STARTINDEX (including) to EndIndex (not included);
Arrays.equals (Array1,array2) returns true if two arrays are equal;
Array.fill (value) sets all elements in the array to the specified value;
Arrays.sort (array) Sorts the contents of the array in ascending order;
Arrays.tostring (array) returns the string representation of the contents of the array;
4. When you print an array, arrays.tostring prints a contiguous string and array.deeptostring prints the array
Accessing an array element with a value less than 0 or greater than the actual length of the array as an index can cause arrayindexoutofboundsexception exceptions.
The first time to write a blog, beginners to learn Java, I hope you have a lot of guidance.