比较器

import java.util.Arrays;

public class MyComparable {

    static class PersonComparable implements
                                  Comparable{
        int nAge;
        String strName;

        public PersonComparable(int nAge, String strName) {
            this.nAge = nAge;
            this.strName = strName;
        }

        @Override
        public String toString() {
            return "Person{" +
                    "nAge=" + nAge +
                    ", strName='" + strName + '\'' +
                    '}';
        }

        @Override
        public int compareTo(PersonComparable o) {
            //自定义比较规则
            if (this.nAge>o.nAge){
                return -1;
            }else if(this.nAge

你可能感兴趣的:(比较器)