-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamExample3.java
More file actions
31 lines (27 loc) · 853 Bytes
/
StreamExample3.java
File metadata and controls
31 lines (27 loc) · 853 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
import java.util.*;
import java.util.stream.*;
class Product {
int id;
String name;
int price;
public Product(int id, String name, int price) {
super();
this.id = id;
this.name = name;
this.price = price;
}
}
public class StreamExample3 {
public static void main(String[] args) {
List<Product> list = new ArrayList<Product>();
list.add(new Product(1,"NoteBook",100));
list.add(new Product(2,"TV",320));
list.add(new Product(3,"Washing Machine",250));
list.add(new Product(4,"Air Conditioner",500));
List<String> result = list.stream()
.filter(p -> p.price > 300)
.map(p -> p.name)
.toList();
System.out.println(result);
}
}