Im a beginner in java and got into a problem using Collection.sort, i have raed more than 15 question in here and got the main idea but still I got stuck in something. first of all a little bit of background, im using this to sort an arraylist of a specific class, and i want to sort it by the name. i need to create an address book, this is how the class is look like:
public class Contact {
private String name;
private String email;
private String phone;
private String address;
this is what i got while look around in here for the comparator
public static class ContactComparator implements Comparator<Contact> {
@Override
public int compare(Contact first, Contact second) {
int f = first.getName().compareTo(second.getName());
return f;
}
}
and this is the command for the sort
Collections.sort(contacts , new ContactComparator());
now this is the problem it gives me:
what is wrong with it? i just can't seems to find it
thank you all very much helpers!