 So here we have one more interview question, so in this video we will be talking about how comparator can be used in Java 8, so there can be questions like sought, the given list of employees based on first name or last name or any other field, but we are making use of comparator, so we will see how can we do that or how the code got reduced So I have one class here, I have already created the employee list, I have six employees, as you can see we have Arun, Dinesh, Chaitanya, Lakshman, Bhargav, Raghed, Arun, Paan, I have created, so let me sort this list based on the name, there is field called name, so I will be sorting that using the name, so here in our course we can see, so this need to have the list, employee list based on what we want to obtain, using method reference, name, that's it, so this will sort based on the first name, to display it, let us have few search, how can we print the list easily, by using for each method So we can have, just I want to print the city as well as the employee, this is my first sort and let me print after the sort, so just I want to copy this list, as sorting logic is already in my list, so save this and I will run this, what is the issue, result compilation Ok, this is sort, six types of column is there, now let us run, so this is the list, firstly if you see the order, before sorting it is not sorted, if you see, however, how we have added the names, Arun, Dinesh, Chaitanya, the same way it got sorted, now see it got sorted with the first name, the card for medical noise I have added to demonstrate it, A, B, C, D, L, so this is how, just write one line of column, now here actually amount of millions of amount of data which is there in the list can be sorted using method reference, now if you want to sort this into the reverse order, that is easy, how, firstly we already have this, just have compare to dot, reverse, see now I will just copy paste this, copy this, turn as reverse, so how, just where you are comparing using first name, just have reverse, save this, this should run now, you can play after reverse sorting, you see your Lakshman was the last guy, your Lakshman is the first guy, Dinesh was last second, he was second, Chaitanya, Chaitanya, Bhargav, Bhargav then Arun, you delay, ok, so this was about sorting and reverse sorting, so now let us discuss about one more thing, like we based on multiple files, we can sort, how we can sort that, now I will demonstrate, firstly we need a comparator of, this is called compile, how we are going to create that, similarly comparator dot, firstly I want to sort based on the first name, so I will sort it based on the first name, dot, then again I want to compare, let me bring this down, so again based on what I want to sort, want to sort, suppose based on city, so here I just, we have one comparator, this is similar to compile function, so let me simply have one, see sort, to differentiate the line, then I will sort, similarly how we have sorted earlier, using same thing we can sort, just have this comparator name here, so see now the magic happens, ok let me print this, now we have print by sorting, so now let us see one, see if we observe this output, so firstly it got sorted based on the name, then it got sorted based on the city, so here we are not able to clearly, what is the difference really, so what I will do, I will change the sorting order, firstly I will change it to city, then I will, here I will make it with name, so that the difference will be clear now, yes see, now first it sorted based on city, so this is how we can do, so this is one of the top interview questions from Java 8, I hope this might be helpful to someone, so it is just logic here is comparator not comparing the method, so we can make use of it and we can sort the things, earlier we used to have a difference comparator class, there we need to, we used to write the comparator method, so now we do not need that, we can directly, this just show lines of code, we can sort the whole amount of data, so that is it with this video, I hope you people like this video and if you haven't subscribed us, you can subscribe us, thank you for watching.