我有一个叫做Contact的对象,它有一堆属性。我还有一个名为Contact_List的联系人数组,我必须为联系人列表编写一个方法,它将为其添加一个联系人对象。这部分很简单,但必须确保其中的所有联系人都是基于姓氏的顺序。我已经有一个名为getLastName的访问器,它返回他们姓氏的字符串,但是如何让该方法添加联系人并订购它们?请帮忙,这是在一个半小时内!如何根据其属性之一订购对象数组?
public void add(Contact frnd)
{
if(numContacts == MAX_CONTACTS) // If the List is already full
{
System.out.println("The Contact List is already at Maximum Capicity");
}
else
{
numContacts += 1; // There is one more Contact
Contact_List[numContacts - 1] = frnd; // Assigns the Last Open Spot the new Contact
}
}
下面是一个例子:http://stackoverflow.com/questions/1946668/sorting-using-comparator-descending-order-user-defined-classes/1947527# 1947527 – camickr 2013-03-22 02:16:14