-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem37.java
More file actions
32 lines (27 loc) · 845 Bytes
/
Problem37.java
File metadata and controls
32 lines (27 loc) · 845 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
package Problems;
// How can you find the 3rd largest element from an integer array using Java 8 Streams?
// {12, 4, 3, 1, 9, 657} -> 9
import java.util.Arrays;
public class Problem37 {
public static void main(String[] args) {
// List<Integer> list= Arrays.asList(12, 4, 3, 1, 9, 657);
//
// int ans=list.stream()
// .sorted((a,b)->Integer.compare(b,a))
// .distinct()
// .skip(2)
// .findFirst()
// .orElse(0);
//
// System.out.println(ans);
int arr[]={12, 4, 3, 1, 9, 657};
int i=3;
int ans= Arrays.stream(arr)
.boxed()
.sorted((a,b)->Integer.compare(b,a))
.skip(i-1)
.findFirst()
.orElse(0);
System.out.println(ans);
}
}