class Person implements Comparator{ private String name=""; public String getName() { return name; } public Person (String name){ this.name=name; } public Person(){ } @Override public int compare(Object o1, Object o2) { if (o1 instanceof Person&&o1 instanceof Person){ Person person1=(Person) o1; Person person2=(Person) o2; if(person1.getName().compareTo(person2.getName())==1){ return 1; } else if (person1.getName().compareTo(person2.getName())==0) return 0; else if(person1.getName().compareTo(person2.getName())==-1){ return -1; } } return 0; } }
05-17
675
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-21