-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamExample.java
More file actions
23 lines (20 loc) · 803 Bytes
/
streamExample.java
File metadata and controls
23 lines (20 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.ArrayList;
import java.util.stream.Stream;
public class streamExample {
public static void main(String[] args) {
ArrayList<Integer> al = new ArrayList<>();
al.add(73);
al.add(3);
al.add(2);
al.add(734);
Stream<Integer> s1 =al.stream().distinct();
Stream<Integer> s2 =al.stream().filter((i)->i%2==0);
Stream<Integer> s3 =al.stream().map((i)->i*i);
Stream<Integer> s4 = al.stream().sorted();
Stream<Integer> s5 = al.stream().sorted((o1,o2)->o2-o1);
System.out.println("Stream Example using filter method: will count the nombers after filter "+s1.count());
s5.forEach(System.out::println);
s2.forEach(System.out::println);
s3.forEach(System.out::println);
}
}