慕后森
我给你看个例子你就知道了这里有一个Person类,里面有firstName and surename2个成员。你的类要实现那个Comparable接口。然后在compareTo函数里决定如果排序,在这个例子里是按照surename排序,surename相同的就按照firstName排序的。希望这个例子对你了解自定义的排序有帮助。import java.util.Arrays;class Person implements Comparable<Person> {public Person(String firstName, String surname) {this.firstName = firstName;this.surname = surname;}public String toString() {return firstName + " " + surname;}public int compareTo(Person person) {int result = surname.compareTo(person.surname);return result == 0 ? firstName.compareTo(((Person) person).firstName) : result;}private String firstName;private String surname;}public class MainClass {public static void main(String[] args) {Person[] authors = { new Person("A", "B"),new Person("C", "D"),new Person("E", "F"),new Person("Z", "Y"),new Person("X", "T"),new Person("O", "R") };Arrays.sort(authors);System.out.println("\nThe cast is ascending sequence is:\n");for (Person person : authors) {System.out.println(person);}}}对于你提到的那个问题,你可以去看卡你 Arrays.sort(a)的代码。