FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java_upgrade/src/main/java/CollectorsDemo.java at main · MikeLaptev/java_upgrade · GitHub
MikeLaptev
/
java_upgrade
Public
forked from
kousen/java_upgrade
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java_upgrade
/
src
/
main
/
java
/
CollectorsDemo.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
43 lines (39 loc) · 1.65 KB
Breadcrumbs
java_upgrade
/
src
/
main
/
java
/
CollectorsDemo.java
Copy path
File metadata and controls
43 lines (39 loc) · 1.65 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
import
java
.
util
.
List
;
import
java
.
util
.
Map
;
import
java
.
util
.
Set
;
import
java
.
util
.
concurrent
.
ConcurrentSkipListSet
;
import
java
.
util
.
function
.
Function
;
import
java
.
util
.
stream
.
Collectors
;
import
java
.
util
.
stream
.
Stream
;
public
class
CollectorsDemo
{
public
static
void
main
(
String
[]
args
) {
var
nums
=
Stream
.
of
(
"this"
,
"is"
,
"a"
,
"collection"
,
"of"
,
"strings"
)
.
parallel
()
.
map
(
String
::
length
)
// .map(n -> {
// System.out.println(n);
// return n;
// })
// equivalent to:
.
peek
(
n
-> {
System
.
out
.
println
(
"On "
+
Thread
.
currentThread
().
getName
()
+
", the value of n before the filter is "
+
n
);
})
.
filter
(
n
->
n
%
2
==
0
)
.
peek
(
n
->
System
.
out
.
println
(
"On "
+
Thread
.
currentThread
().
getName
()
+
", the value of n after the filter is "
+
n
))
.
toList
();
System
.
out
.
println
(
nums
);
var
set
=
Stream
.
of
(
"this is a is a collection of strings"
.
split
(
" "
))
.
collect
(
Collectors
.
toSet
());
System
.
out
.
println
(
set
);
System
.
out
.
println
(
set
.
getClass
().
getName
());
var
collection
=
Stream
.
of
(
"this is a is a collection of strings"
.
split
(
" "
))
.
collect
(
Collectors
.
toCollection
(
ConcurrentSkipListSet
::
new
));
var
stringMap
=
Stream
.
of
(
"this is a collection of strings"
.
split
(
" "
))
.
collect
(
Collectors
.
toMap
(
Function
.
identity
(),
String
::
length
));
System
.
out
.
println
(
stringMap
);
}
}
Back
|
FazBrowse Home
|
New Git URL