-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapFunctionn.java
More file actions
27 lines (19 loc) · 807 Bytes
/
Copy pathMapFunctionn.java
File metadata and controls
27 lines (19 loc) · 807 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
package stream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class MapFunctionn {
public static void main(String[] args) {
List<Integer> l=Arrays.asList(56,3,98,42,9,2,89,5,45,9,0,5,9);
List<Integer> list1=l.stream().distinct().collect(Collectors.toList()); //find unique element from stream
System.out.println(list1);
List<Integer> list2=l.stream().dropWhile(num->num%2==0).collect(Collectors.toList());
System.out.println(list2);
List<Integer> list3=l.stream().filter(num->num>=70).collect(Collectors.toList());
System.out.println(list3);
Optional<Integer>max=l.stream().max((n1,n2)->n1>n2?1:n1<n2?-1:0);
System.out.println(max.get());
}
}