-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStream2.java
More file actions
33 lines (27 loc) · 917 Bytes
/
Copy pathStream2.java
File metadata and controls
33 lines (27 loc) · 917 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
33
import java.util.*;
import java.util.stream.Collectors;
class Product {
int id;
String name;
float price;
Product(int id, String name, float price) {
this.id = id;
this.name = name;
this.price = price;
}
}
public class Stream2 {
public static void main(String[] args) {
List<Product> pl = new ArrayList<Product>();
pl.add(new Product(1,"HP Laptop",25000f));
pl.add(new Product(2,"Dell Laptop",30000f));
pl.add(new Product(3,"Lenevo Laptop",28000f));
pl.add(new Product(4,"Sony Laptop",28000f));
pl.add(new Product(5,"Apple Laptop",90000f));
List<Float> result = pl.stream()
.filter(p -> p.price > 28000)
.map(p -> p.price)
.collect(Collectors.toList());
System.out.println(result);
}
}