-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamApi.java
More file actions
36 lines (24 loc) · 1.21 KB
/
Copy pathStreamApi.java
File metadata and controls
36 lines (24 loc) · 1.21 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
package stream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class StreamApi {
public static void main(String[] args) {
List<Integer> i=Arrays.asList(48,67,89,90,34,23,545,78,90,23);
System.out.println(i);
List<Integer> evenlist=i.parallelStream().dropWhile((ele)->ele%2==0).toList();
//dropwhile method is method of stream which is used to drop the the element from given stream according to predicate
System.out.println(evenlist);
List<Integer> map=evenlist.stream().map((ele)->ele+1).toList();
//map is the method of stream which is used to apply the some functionality to method
System.out.println(map);
System.out.println(map.stream().anyMatch((ele)->ele==24)? "element present":"element not present");
//anymatch is method of stream class which is return boolean value according to predicate
System.out.println(i.stream().findAny().get());//this is used to find anny element randomly
System.out.println(i.stream().findAny().get());//this is used to find anny element randomly
}
}