I want to sort Collection of Objects, which does not implement comparable or comparater interface. The problem is I cannot change the class design because I have only .class(no source code) file. How can I achive this?
I want to sort Collection of Objects, which does not implement comparable or comparater
Share
You can sort by providing a custom Comparator. You don’t need to implement Comparable.
See Collections.sort(List s, Comparator c) and the Collections ordering tutorial – specifically the section labelled Comparators: