5.6 |
---|
4.5 |
1.37 |
8.98 |
11.345 |
0.66 |
arr[5]
arr[4]
arr[3]
arr[2]
arr[1]
arr[0]
double[] arr = new double[6];
reference |
---|
arr
Array reference variable
Array element
at index 3
Element value
arr.length
int[] arr = {1, 2, 3, 4, 5, 6};
arr[3]
Scanner s = new Scanner(System.in);
int[] arr = new int[5];
for (int i = 0; i < arr.length; i++) {
int num = s.nextInt();
arr[i] = num;
}
int[] arr = {1, 2, 3, 4, 5};
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
int[] arr = {1, 2, 3, 4, 5};
for (int num : arr) {
System.out.println(arr);
}
int[] sourceArr = {1, 2, 3, 4, 5};
int[] targetArr = new int[sourceArr.length];
Definition:
System.arraycopy(sourceArr, sourcePos, targetArr, targetPos, length)
System.arraycopy(sourceArr, 0, targetArr, 0, sourceArr.length);
declare and initialize source and target array
using a for-loop
for (int i = 0; i < sourceArr.length; i++) {
targetArr[i] = sourceArr[i];
}
using System.arraycopy(...)
// sort an array
Arrays.sort(arr);
// search in an array
Arrays.binarySearch(arr, key);
// convert array to list
Arrays.asList(arr);
// from java 8
Arrays.stream(arr);