-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathJava8FlatMap.java
More file actions
executable file
·91 lines (69 loc) · 1.87 KB
/
Copy pathJava8FlatMap.java
File metadata and controls
executable file
·91 lines (69 loc) · 1.87 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.programcreek.java8.stream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
public class Java8FlatMap {
public static void main(String[] args) {
ArrayList<Order> orders = new ArrayList<Order>();
Stream<Item> itemStream = orders.stream().flatMap(order -> order.getItems().stream());
}
public static Stream<Character> convertToCharStream(String s){
ArrayList<Character> list = new ArrayList<Character>();
for(char c: s.toCharArray()){
list.add(c);
}
return list.stream();
}
public static void test() throws IOException{
Path path = Paths.get(null);
Stream<String> lines = Files.lines(path, StandardCharsets.UTF_8);
Stream<String> words = lines.flatMap(line -> Stream.of(line.split(" +")));
}
}
class Order{
String orderId;
ArrayList<Item> items = new ArrayList<Item>();
public Order(String orderId, ArrayList<Item> orderItems) {
super();
this.orderId = orderId;
this.items = orderItems;
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public ArrayList<Item> getItems() {
return items;
}
public void setItems(ArrayList<Item> orderItems) {
this.items = orderItems;
}
}
class Item{
String itemId;
String itemName;
public Item(String itemId, String itemName) {
super();
this.itemId = itemId;
this.itemName = itemName;
}
public String getItemId() {
return itemId;
}
public void setItemId(String itemId) {
this.itemId = itemId;
}
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
}