我有这堂课:
public class Contact {
private String firstname;
private String lastname;
private List<Integer> phoneNumber;
private Scanner in;
public Contact(){
phoneNumber = new ArrayList<>();
firstname = lastname = "";
in = new Scanner(System.in);
}
public void setFirstName(){
firstname = in.nextLine();
}
public void setLastName(){
lastname = in.nextLine();
}
public void setPhoneNumber(){
phoneNumber.add(in.nextInt());
}
public String getFirstName(){
return firstname;
}
public String getLastName(){
return lastname;
}
public Integer getPhoneNumber(int position){
return phoneNumber.get(position);
}
}
现在我想做一个有我的联系人的类电话簿..我想用
Arraylist<Contact>
因为它没有固定大小。当我想按姓氏对这个数组列表进行排序时,我会怎么做?