Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Java8Practies
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
Uma Vani Ravuri
Java8Practies
Commits
6233967f
Commit
6233967f
authored
Sep 23, 2021
by
Uma Vani Ravuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace TestEmployee.java
parent
01c110e6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
1 deletion
+14
-1
TestEmployee.java
...8PractiesProgram/src/com/java8/practies/TestEmployee.java
+14
-1
No files found.
Java8PractiesProgram/src/com/java8/practies/TestEmployee.java
View file @
6233967f
package
com
.
java8
.
practies
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -9,6 +10,7 @@ import java.util.function.Function;
import
java.util.stream.Collector
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
java.util.Collection
;
public
class
TestEmployee
{
public
static
void
main
(
String
[]
args
)
{
...
...
@@ -92,14 +94,25 @@ public class TestEmployee {
listEmp
.
stream
().
filter
(
x
->
!
x
.
getDepartmentNames
().
stream
().
equals
(
"EEE"
))
.
collect
(
Collectors
.
toList
()).
forEach
(
System
.
out
::
println
);
//given a list of employees. Can you create a map with the count of employees each department has ?
//with key as department name and count of employees as value.
Stream
<
String
>
distinctDept
=
listEmp
.
stream
()
.
map
(
Employee:
:
getDepartmentNames
)
.
flatMap
(
x
->
x
.
stream
()
);
.
flatMap
(
Collection:
:
stream
);
Map
<
String
,
Long
>
mapDepartment
=
distinctDept
.
collect
(
Collectors
.
groupingBy
(
Function
.
identity
(),
Collectors
.
counting
()));
mapDepartment
.
forEach
((
k
,
v
)
->
System
.
out
.
println
((
k
+
":"
+
v
)));
//Given a map with the department name as key and value as list of employees belonging to that department.
Map
<
List
<
String
>,
List
<
Employee
>>
mapEmployee
=
listEmp
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
Employee:
:
getDepartmentNames
,
Collectors
.
toList
()));
mapEmployee
.
forEach
((
k
,
v
)
->
System
.
out
.
println
((
k
+
":"
+
v
)));
}
...
...
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