If you have any feedback on the Java collections tutorials in this section or about the content of this site in general, you need to implement method compareTo. You need it to compare objects, in order to use, for example, please leave a message on the Javamex forum. You need a way to compare your objects to be able to sort them. So you need a custom compareTo method in your class so you can use it with the ArrayList sort method. Link-only answers can become invalid if the linked page changes. CountrySortByIdComparator which will implement Comparator interface and implement compare method to sort collection of country object by id and we will also see how to use anonymous comparator. Neil Coffey. Copyright © Javamex UK 2012. All rights reserved. Comparable interface, sorting method of ArrayList class.