Java Sort List of Objects with Comparator

This tutorial shows you way to Sort List of Objects by implementing Comparator example.

Related Post: Java Sort List of Objects with Comparable

How to do this with Kotlin: Sort List of Objects with Comparator

I. Overview

1. Goal

Sort list of three MyDate(year,month,day) objects.

2. Steps to do

– Implement Comparator interface for the class that you use for handling sorting.
– Override compare(T object1, T object2) method and:
+ return zero if object1 is equal object2
+ a negative number if object1 is less than object2
+ a positive number if object1 is greater than object2
– Use sort(Comparator) method.

II. Practice

1. Create Class for objects to be sorted

2. Create Class for handling sorting

3. Create test function

4. Run & check Result

By grokonez | June 22, 2017.

Related Posts

Got Something To Say:

Your email address will not be published. Required fields are marked *