Sorting an ArrayList that contains custom objects


You need to implement a Comparator for instance:

public class FishNameComparator implements Comparator<Fish>
    public int compare(Fish left, Fish right) {

and then sort it like this:

Collections.sort(fishes, new FishNameComparator());

Leave a Reply

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