Java 8: Sorting of Collection using lambda Expression
In my previous blog, I have already discussed on Lambda Expression and its Syntax as well as Functional Interface. So, if you are not aware of then I would suggest you to read those blogs before starting this one. http://www.waheedtechblog.com/2019/01/how-to-write-lambda-expression-in-java-8.html http://www.waheedtechblog.com/2019/01/functional-interface-and-lambda.html As we know Comparator Interface is also a Functional Interface as it has only one abstract method. In this blog, we will see how we can do sorting using lambda expression. Let’s start with List and will cover Set, Map as well as Custom Class as well. List Sorting of elements on any Array List can be done easily using Collections.sort(…) functions where sort() can take argument as list or with list, you can also pass comparator object. In below example, we will see how can we sort using comparator and the same task with lambda expression. Output: 2 2. ...