Java Comparator Using Lambda

Learn how to use the power of lambdas to write a concise comparator.

If you’ve been working with Java for some time, then you’ve probably encountered a scenario where you need to sort the elements in a collection.

If your collection contains a wrapper class object then the sorting is very easy. Since all the wrapper classes implement the Comparable interface, you can directly use Collections.sort() to sort your collection.

However, if your collection contains a custom class ...