-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayMethod.java
More file actions
53 lines (53 loc) · 1.6 KB
/
ArrayMethod.java
File metadata and controls
53 lines (53 loc) · 1.6 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
44
45
46
47
48
49
50
51
52
53
import java.util.Arrays;
public class ArrayMethod{
public static void printArray(int arg[]){
for(int i=0;i<arg.length;i++){
System.out.println(arg[i]);
}
}
public static void main(String arg[]){
int[] arr = {1,2,3,4,5,6};
int[] unsort = {1,6,4,5,3,2};
int[] arr2 = {1,2,3,4,5,6};
int[] dest=new int[10];
//sort array
Arrays.sort(arr);
//print length
System.out.print("Length of an array");
System.out.println(arr.length);
System.out.println("Binary Search of number 3");
//apply binary search and print results
System.out.println(Arrays.binarySearch(arr, 3));
//create a copy of array truncated or padded with zero based on size
//of new array
int[] arrCopy=Arrays.copyOf(arr,10);
System.out.println("copy of array printed");
printArray(arrCopy);
//copy of range
System.out.println("Copy Into Range");
int[] copyIntoRange=Arrays.copyOfRange(arr,0,10);
//printing array
printArray(copyIntoRange);
//equals method
System.out.println("Equals Method in arrays");
System.out.println(Arrays.equals(arr,arr2));
//fill method
Arrays.fill(arr2,2);
//printing filled array
System.out.println("filled array with 2");
printArray(arr2);
//filling in specific range
Arrays.fill(arr2,2,4,0);
//print array
System.out.println("filling in specific range");
printArray(arr2);
//sorting in specific range
Arrays.sort(unsort,2,5);
//print sorted array from 2 to 4 index
System.out.println("Print Sorted Array");
//print sorted array
printArray(unsort);
//print array converted to string
System.out.println(Arrays.toString(unsort));
}
}