8 ways to Sort List in Java 8 using Lambda Expression + Method Reference - Example Tutorial

Hello guys, as a Java developer we often need to sort List like ArrayList, LinkedList, or CopyOnWriteArrayList and while I have share many articles on sorting a list in Java in both increasing order  and deceasing order as well as sorting ArrayList in a custom order using Comparator, things have changed a lot in Java world, especially after Java 8 when Lambda expression and method reference was first introduced. Now there are more declarative and expressive way to sort a List of object in different order based upon different conditions. Enhancements made on Comparator API has also made comparing and sorting object in Java much easier and I have shown the power of new Comparator API in my earlier article about advanced Java Comparator example. I was particularly impressed with comparing() and thenComparing() as they literally make comparison on multiple condition easier. 

Post a Comment