Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Projet GORDYJAN_BAGNOLY_GARCIA_POIGNONNEC
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
POIGNONNEC
Projet GORDYJAN_BAGNOLY_GARCIA_POIGNONNEC
Commits
f11795ea
Commit
f11795ea
authored
May 20, 2019
by
GORDYJAN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Main.java with Streams
parent
f2ee5d89
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
+51
-0
Main.java
src/main/java/openclassroom/Main.java
+51
-0
No files found.
src/main/java/openclassroom/Main.java
View file @
f11795ea
package
openclassroom
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.stream.Stream
;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
List
<
Personne
>
listP
=
Arrays
.
asList
(
new
Personne
(
1.80
,
70
,
"A"
,
"Nicolas"
,
Couleur
.
BLEU
),
new
Personne
(
1.56
,
50
,
"B"
,
"Nicole"
,
Couleur
.
VERRON
),
new
Personne
(
1.75
,
65
,
"C"
,
"Germain"
,
Couleur
.
VERT
),
new
Personne
(
1.68
,
50
,
"D"
,
"Michel"
,
Couleur
.
ROUGE
),
new
Personne
(
1.96
,
65
,
"E"
,
"Cyrille"
,
Couleur
.
BLEU
),
new
Personne
(
2.10
,
120
,
"F"
,
"Denis"
,
Couleur
.
ROUGE
),
new
Personne
(
1.90
,
90
,
"G"
,
"Olivier"
,
Couleur
.
VERRON
)
);
Stream
<
Personne
>
sp
=
listP
.
stream
();
sp
.
forEach
(
System
.
out
::
println
);
System
.
out
.
println
(
"\nAprès le filtre"
);
sp
=
listP
.
stream
();
sp
.
filter
(
x
->
x
.
getPoids
()
>
50
)
.
forEach
(
System
.
out
::
println
);
System
.
out
.
println
(
"\nAprès le filtre et le map"
);
sp
=
listP
.
stream
();
sp
.
filter
(
x
->
x
.
getPoids
()
>
50
)
.
map
(
x
->
x
.
getPoids
())
.
forEach
(
System
.
out
::
println
);
System
.
out
.
println
(
"\nAprès le filtre et le map et reduce"
);
// Attention reduce consomme le stream et le rend inutilisable
sp
=
listP
.
stream
();
Double
sum
=
sp
.
filter
(
x
->
x
.
getPoids
()
>
50
)
.
map
(
x
->
x
.
getPoids
())
.
reduce
(
0.0d
,
(
x
,
y
)
->
x
+
y
);
System
.
out
.
println
(
sum
);
/*
long count = sp .filter(x -> x.getPoids() > 50)
.map(x -> x.getPoids())
.count();
System.out.println("Nombre d'éléments restant après opérations : " + count);
sp = listP.stream();
List<Double> ld = sp.filter(x -> x.getPoids() > 50)
.map(x -> x.getPoids())
.collect(Collectors.toList());
System.out.println(ld); //récupère les informations sous le format défini, ici une liste
*/
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment