You need to implement a Comparator
, for instance:
public class FishNameComparator implements Comparator<Fish>
{
public int compare(Fish left, Fish right) {
return left.name.compareTo(right.name);
}
}
and then sort it like this:
Collections.sort(fishes, new FishNameComparator());
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…