-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamExample.java
More file actions
32 lines (23 loc) · 844 Bytes
/
StreamExample.java
File metadata and controls
32 lines (23 loc) · 844 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
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
public class StreamExample {
/**
* @param args
*/
public static void main(String[] args) {
List<String> listofNames = new ArrayList<String>();
listofNames.add("Bdasan");
listofNames.add("Manickam");
listofNames.add("Alimran");
listofNames.add("Bharathi");
//Using the Stream and Lambda expression
long countVal=listofNames.stream().filter(names->names.length()<9).count();
System.out.println("There are "+countVal+" strings with length less than 7");
//operations are lazy in nature, which means they are not executed until they are needed
Stream.iterate(1, count->count+1)
.filter(number->number%3==0)
.limit(6)
.forEach(System.out::println);
}
}