 So hi guys, welcome back The channel so in this video like I'll be sharing you one of the interview question that I have faced with HCL So it was a virtual interview. So it was happening through zoom. So employees said me like interviewer has sent me There is an Employee list so in employee list employee has Sorry name ID CD and age this way the four things that the employee object has so I was given employee list and he was he asked me to filter out employees based on their age like if the age is greater than 25 I should get all the employees. So I was asked to write this So I have written it. I was to be honest I have used notepad because I have used the notepad There is one reason because whenever you are using even though I was having eclipse I still prefer to use notepad because whenever I use a notepad that Actually showcases the confidence that I have in my coding skills to be honest like even five place You develop years of experience developers hesitate to write the core and like notepad because they're habituated to writing code on Eclipse using cause that gives us suggestions to be honest We are working in the production environment or in the real-time projects that is really helpful But whenever you are attending interviews always try to write it on in plain papers or on the notepad if it is Because that shows your confidence like how much confidence you are in on your coding skills. So let me quote employee list Stream filter What we get we get an employee What dot get age Greater than 25 so let me Dot collect collectors dot To list so this should give you the output for us. So where I can hold it So, let me see let me copy paste this same code in eclipse and see whether this will work or not So I have already created an employee list and if I paste it what are the exceptions? I get okay I need to import collectors control ship for Then it got important now. I want to hold this list Employee Output list Sorry, okay employee. I will copy paste from here So I got it now if I want to print this out. I can use directly For each dot for each For each and go take it employee object Take it as I have already written a toasting method in the employee class. I will I can directly print this employee object Self, so let me run this program Right click run as run as Java application So I got two employees Richard and and wish so So Richard by an and wish are having 27 and 29 age and as they are greater than 25. So we got This output now the next question was here. So here the age is highest age is 29. So I'll apply filter 30 so he asked me to change this logic and he asked me what will be the output now Will there be a null pointer exception because this won't return anything or this would be an empty list or Will this what will this print here? What will happen? So? Here to be honest like Nothing will happen or this will return an empty So let me run Nothing will get printed the application the program will get terminated what happened So it won't even show you the output. Let me Have a sis out and print This output list now you will come to know What it has printed Nothing on so empty list is getting printed. So don't get confused that it might Throw a null pointer here. It won't throw. So let me come back to my previous example 25 So now we have used filter. So in what scenario we are going to use map So what is the purpose of map here? So basically we use filter to reduce the existing employee like existing list based on some predicate if it is five all the List objects are passing the predicate the now the entire list will be written as a but if you want to use map map will be Operated on each and every object Suppose see I have employ list, right? So let me take this again one more example Employ list Dot map What I'm doing he employ get So in this scenario What I am doing? I want to have employee all the Employer names in that list which are present in that list. So I can directly copy paste this Collector's dot to list here and This to hold that value. Let me have one more variable declared output map and That's it. Oh, sorry. This should be a string. Sorry as I'm returning only List of employees, that's it. Now you can directly print this map No, see I just come in from commenting over the first for each You can directly have the second See I got all the list of names. So basically filter will reduce Based on the predicate, but map will act on each object here and it will return that object So I'm just getting the name here. So I So this is the basic difference like it will return the entire whatever stream It is acting upon or whatever list of objects that is acting upon it will retain the same object The same list the size would be the same thing. So this is one of the Interview question that I wanted to share Thank you for watching. That's it Hey guys, if you think Our videos are helping you out and if you want to contribute us in some way So before your next purchase on Amazon, you can do one thing just open YouTube search our channel From the latest we videos open any video Stop it here. You can see an Amazon link to one of the best books here So if you want to purchase this book, you can purchase this book or else you can like whatever you want to buy You can open that Item or you can search that item directly and you can buy that if you buy that Through our link we might get 1% or 2% of the total amount you spend on that You may not get any discount on that but we may get some money out of it So don't forget to do this before your next purchase on Amazon. Thank you