FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java8-tutorial/src/com/winterbe/java8/Streams7.java at master · lan13217/java8-tutorial · GitHub
lan13217
/
java8-tutorial
Public
forked from
winterbe/java8-tutorial
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
java8-tutorial
/
src
/
com
/
winterbe
/
java8
/
Streams7.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
61 lines (48 loc) · 1.35 KB
Breadcrumbs
java8-tutorial
/
src
/
com
/
winterbe
/
java8
/
Streams7.java
Copy path
File metadata and controls
61 lines (48 loc) · 1.35 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
com
.
winterbe
.
java8
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
List
;
import
java
.
util
.
stream
.
IntStream
;
/**
* @author Benjamin Winterberg
*/
public
class
Streams7
{
static
class
Foo
{
String
name
;
List
<
Bar
>
bars
=
new
ArrayList
<>();
Foo
(
String
name
) {
this
.
name
=
name
;
}
}
static
class
Bar
{
String
name
;
Bar
(
String
name
) {
this
.
name
=
name
;
}
}
public
static
void
main
(
String
[]
args
) {
// test1();
test2
();
}
static
void
test2
() {
IntStream
.
range
(
1
,
4
)
.
mapToObj
(
num
->
new
Foo
(
"Foo"
+
num
))
.
peek
(
f
->
IntStream
.
range
(
1
,
4
)
.
mapToObj
(
num
->
new
Bar
(
"Bar"
+
num
+
" <- "
+
f
.
name
))
.
forEach
(
f
.
bars
::
add
))
.
flatMap
(
f
->
f
.
bars
.
stream
())
.
forEach
(
b
->
System
.
out
.
println
(
b
.
name
));
}
static
void
test1
() {
List
<
Foo
>
foos
=
new
ArrayList
<>();
IntStream
.
range
(
1
,
4
)
.
forEach
(
num
->
foos
.
add
(
new
Foo
(
"Foo"
+
num
)));
foos
.
forEach
(
f
->
IntStream
.
range
(
1
,
4
)
.
forEach
(
num
->
f
.
bars
.
add
(
new
Bar
(
"Bar"
+
num
+
" <- "
+
f
.
name
))));
foos
.
stream
()
.
flatMap
(
f
->
f
.
bars
.
stream
())
.
forEach
(
b
->
System
.
out
.
println
(
b
.
name
));
}
}
Back
|
FazBrowse Home
|
New Git URL