-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample2.java
More file actions
43 lines (39 loc) · 1.8 KB
/
Example2.java
File metadata and controls
43 lines (39 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.tutorial.def;
import java.util.Arrays;
public class Example2 {
public static void main(String[] args) {
int[] intArray = new int[9];
Arrays.fill(intArray, 123);
System.out.println(Arrays.toString(intArray));
Arrays.fill(intArray, 3, 7, 234);
System.out.println(Arrays.toString(intArray));
int[] ints = {6, 8, 10, 4, 2, 12, 14, 16, 0, 12, 22, 20};
int index = Arrays.binarySearch(ints, 8);
System.out.println(ints.length + ", " + index);
Arrays.sort(ints);
int key = 5;
index = Arrays.binarySearch(ints, key);
System.out.println(key + ", " + Arrays.toString(ints) + ", " +index);
key = 10;
index = Arrays.binarySearch(ints, key);
System.out.println(key + ", " + Arrays.toString(ints) + ", " +index);
key = 23;
index = Arrays.binarySearch(ints, key);
System.out.println(key + ", " + Arrays.toString(ints) + ", " +index);
key = 2;
index = Arrays.binarySearch(ints, 0, 4, key);
System.out.println(key + ", " + "fromIndex: " + 0 + " toIndex: " + 4 + ", " + Arrays.toString(ints) + ", " +index);
key = 23;
index = Arrays.binarySearch(ints, 0, 4, key);
System.out.println(key + ", " + "fromIndex: " + 0 + " toIndex: " + 4 + ", " + Arrays.toString(ints) + ", " +index);
key = 5;
index = Arrays.binarySearch(ints, 0, 4, key);
System.out.println(key + ", " + "fromIndex: " + 0 + " toIndex: " + 4 + ", " + Arrays.toString(ints) + ", " +index);
int[] ints1 = {1, 2, 3, 4};
int[] ints2 = {1, 2, 3, 4};
int[] ints3 = {4, 2, 3, 1};
System.out.println(Arrays.equals(ints1, ints2));
System.out.println(Arrays.equals(ints1, ints3));
// Accessing an Array via Reflection
}
}