It's been quite some time I share a technical post with you, so today, I am sharing some advanced examples of Comparable and Comparator in Java to compare objects on multiple fields like name, address, age, and more.
Both Comparator and Comparables are used to compare objects but they are not easy to implements, especially when you want them to use in the real world as you may need to sort on multiple fields, maybe some fields will be required to sort in reverse order and so on.
It was tricky before Java 8 but after Java 8 it's a lot easier because now you can chain comparators using thenComparing() and you have access to more powerful methods like to sort in reverse order and more. I have discussed all of them in this article, if you haven't read it yet, you can read it now to revise your Comparator concepts.
Here is the link to the article - 6 Advanced Comparator and Comparable Examples in Java
JavinRead more - How to compare Java objects on multiple fields?