I have this class:
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);
}
}
Now I want to make a class PhoneBook which have my contacts.. I thought to make it with
Arraylist<Contact>
because it won't have a fixed size.. When I want to sort this arraylist by Lastname what would I do?