int[] array;
или
int otherArray[];
int[] array = new int[5];
int[] array = new int[] {1, 2, 3, 4, 5, 6, 7, 8};
int[] array = new int[] {1, 2, 3, 4, 5, 6, 7, 8};
array[0] = 9;
System.out.println(array[0]);
int[] array = new int[] {1, 2, 3, 4, 5, 6};
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
int[] array = new int[] {1, 2, 3, 4, 5, 6};
for (int e : array) {
System.out.println(e);
}
void method(int... varargs) {}
int[] array = new int[] {1, 2, 3};
method(array);
method(1, 2, 3);
Integer[] array = new Integer[] {10, 20, 30};
List<Integer> list = new ArrayList<>();
for (int e : array) {
list.add(e);
}
Integer[] array = new Integer[] {10, 20, 30};
List<Integer> list = Arrays.asList(array);
String[] array = new String[] {"Java", "Python", "C#"};
Stream<String> stream = Arrays.stream(array);
String[] array = new String[] {"Java", "Python", "C#"};
Stream<String> otherStream = Arrays.stream(array, 1, 3);
int[] array = new int[] {8, 3, 1, 0, 9};
Arrays.sort(array);
// array = {0, 1, 3, 8, 9}
Integer[] otherArray = new Integer[] {7, 2, 1, 4, 3};
Arrays.sort(otherArray);
// otherArray = {1, 2, 3, 4, 7}
String[] sArray = new String[] {"A", "E", "D", "B", "C"};
Arrays.sort(sArray, 1, 3,
Comparator.comparing(String::toString).reversed());
// sArray = {"A", "D", "E", "B", "C"}
int[] array = new int[] {7, 2, 3, 4, 8};
for (int i = 0; i < anArray.length; i++) {
if (anArray[i] == 2) {
System.out.println("index = " + i);
break;
}
}
int[] array = new int[] {1, 2, 3, 4, 5, 6};
int index = Arrays.binarySearch(array, 5);
System.out.println("index = " + index);
int[] array = new int[] {5, 3, 7, 4, 8};
int[] otherArray = new int[] {10, 6, 9, 11, 3};
int[] result = new int[array.length + otherArray.length];
for (int i = 0; i < result.length; i++) {
result[i] = (i < array.length ? array[i] : otherArray[i - array.length]);
}
int[] array = new int[] {5, 3, 7, 4, 8};
int[] otherArray = new int[] {10, 6, 9, 11, 3};
int[] result = new int[array.length + otherArray.length];
Arrays.setAll(result, i -> (i < array.length ? array[i] : otherArray[i - array.length]));
System.arraycopy(array, 0, result, 0, array.length);
System.arraycopy(otherArray, 0, result, array.length, otherArray.length);