 Hi guys today I would like to talk about one of the most important interview questions that is related to Java 8. So only the question is like there is a list of employees and we need to convert that list of employees to a map and basically the map the final output should be the key should be the city name and the list of employees who are studying density for example I have taken five employees like there are five employees only like last tour residing in Bangalore if you see here these two are the people who are residing in Bangalore so for the final output should be the key value for the city and the number of people that has got thus heavily in the city so I have taken the employee list so here we can sort it out like the log in course something like this so as in go by function we can achieve this or the reason for sharing this question is recently most of my interviews this question was asked so collect and collectors are grouping by I will take this code line by line collectors are grouping by here based on what we can do based on city so this is method reference here that's it this is the logic that will work for us so to hold this I will create a app of string as a key and list of employees so here are employees here from here I will copy this this is a employee and this is employee what's wrong here what it is saying in my case maybe the input is control shift oh yeah that's it there's the important problem so everything is fine this is how we can get if you can format it oh it's going to one single line okay so remove the formatting that logic so basically the logic is the employee list dot stream dot collect and our logic so whatever grows in the collect here is basically making use of grouping by function and method reference we can get this so to print this employee map now I can go with control is here okay dot each so instead for each we value pair will come basically key would be the city and value would be the employees so this is a lambda here and I go in this out yeah so let me break this into okay let me break this up and city this is the key and employees in that city let's value okay so here small we that's it if I run this program now we should probably okay various uh I'll shortcut this console okay and maximize the console so let's just see here so in the Bangalore they said the term implies yeah later Kalyan ID five and Lakshman ID four are the top people who reside in Bangalore so we got that so basically the core logic is this the common we don't so basically most of them you might not have getting the idea so it is good practice in necklace was so basically like an introduction he's a private he's having XYZ things and if you can write it without saying that would be better stream dot collect dot stream dot collect inside this collectors dot grouping by the ROUP group in by and but hopefully this should work if I just copy paste it this logic should go maybe uh the naming convention what I give might be wrong but it should work still okay okay okay what happened so yeah employ list maybe different thing and saving this run it what is the error what did he say okay okay we'll come that's it and this which you know from give me the same okay let me see what happens it is a bit clear around the application so this is the city and we have to apply so this is one of the important questions and recently like we have started this series now we will be sharing all the coding questions that we have encountered in java because this is uh becoming a more most important factor this this to not to get selected mostly the entire questions on is on java so this is one of the key factors so here what all we use we have we have streams we have used lambdas we have used for each method and we have used method reference so all these things came up in java so with this one example you can demonstrate four things like you have hands on experience on four things so this is one thing we would we wanted to share so we have shared this want to people like it or this might help you in cracking your interviews so and thanks for watching so basically the concept is this how or else there are other ways where we can convert a list of map and in the upcoming videos we will share that as well how to convert a list into map so for this that's it for now