From the course: Functional Programming with Java

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Solution: Average salary calculator

Solution: Average salary calculator - Java Tutorial

From the course: Functional Programming with Java

Start my 1-month free trial

Solution: Average salary calculator

(upbeat music) - [Instructor] Okay, so let's take a look at how I went about converting this list of employees into a map that contains all the different job titles as well as the associated average salary for that job title. So, first of all, I knew that the answer here should be a map where the key is a string, and the corresponding value for each key is a float. Which is going to be the average salary for each group of employees. And of course we need to import map and I called this average salaries map, okay? And what I did next, was I said employees and converted that to a stream, okay? And then I said, dot collect, and I used the collectors.groupingby collector to group all of the employees by their job title. So what I did for that function that I passed to it, 'cause I said employee and simply returned employee.jobtitle, okay? And just ignore these red squiggly lines for now it's going to keep doing that until I get to the very end. So at this point what we have is a map that…

Contents