java comparator, how to sort by integer?

后端 未结 6 992
一整个雨季
一整个雨季 2020-12-08 09:36

Im trying to learn comparator in java and I have found this great example online, my question is how would this code be changed so that the pet names are ordered by age and

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 09:55

    public class DogAgeComparator implements Comparator {
        public int compare(Dog o1, Dog o2) {
            return Integer.compare(o1.getAge(), o2.getId());
        }
    }
    

提交回复
热议问题