FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java_upgrade/src/main/java/lambdas/UsePerson.java at master · sairam-github/java_upgrade · GitHub
sairam-github
/
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
/
lambdas
/
UsePerson.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
29 lines (21 loc) · 882 Bytes
Breadcrumbs
java_upgrade
/
src
/
main
/
java
/
lambdas
/
UsePerson.java
Copy path
File metadata and controls
29 lines (21 loc) · 882 Bytes
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
package
lambdas
;
import
java
.
util
.
Arrays
;
import
java
.
util
.
List
;
import
java
.
util
.
stream
.
Collectors
;
public
class
UsePerson
{
@
SuppressWarnings
({
"UnusedAssignment"
,
"Convert2MethodRef"
})
public
static
void
main
(
String
[]
args
) {
List
<
String
>
names
=
Arrays
.
asList
(
"John"
,
"Paul"
,
"George"
,
"Ringo"
);
List
<
Person
>
people
=
names
.
stream
()
// Stream<String>
.
map
(
name
->
new
Person
(
name
))
// Stream<Person>
.
collect
(
Collectors
.
toList
());
// Converts Stream<Person> to List<Person>
people
=
names
.
stream
()
.
map
(
Person
::
new
)
.
collect
(
Collectors
.
toList
());
System
.
out
.
println
(
people
);
Person
[]
peopleArray
=
names
.
stream
()
.
map
(
Person
::
new
)
.
toArray
(
Person
[]::
new
);
System
.
out
.
println
(
Arrays
.
toString
(
peopleArray
));
}
}
Back
|
FazBrowse Home
|
New Git URL