-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInbuiltSort.java
More file actions
43 lines (32 loc) · 955 Bytes
/
InbuiltSort.java
File metadata and controls
43 lines (32 loc) · 955 Bytes
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 Sorting;
import java.util.Arrays;
import java.util.Comparator;
public class InbuiltSort{
public static void main(String[] args) {
Integer arr[] = { 10, 9, 8, 6, 5, 4, 3, 2, 11, 16, 8 };
// Arrays.sort(arr);
// for (int x : arr) {
// System.out.print(x + " ");
// }
// System.out.println();
// Reverse the array using Inbuilt Functions
// Collections.reverse(Arrays.asList(arr));
// for(int x : arr)
// {
// System.out.print(x + " ");
// }
//Sorting using comparator Functions
Arrays.sort(arr, new Comparator<Integer>() {
@Override
public int compare(Integer a, Integer b)
{
return b - a;
}
});
int n = arr.length;
for(int i=0;i<n;i++)
{
System.out.print(arr[i] + " ");
}
}
}