I am trying to sort a linked list and keep getting "no suitable method found for sort(LinkedList,>). What am I doing wrong?
public Contributor(String firstName, String lastName, String city,
String country, String phone, double contribution, int id) {
// CONSTRUCTOR WITH ALL ATTRIBUTES PASSED
this.firstName = firstName;
this.lastName = lastName;
this.country = country;
this.phone = phone;
this.contribution = contribution;
this.id = id;
}
public static LinkedList<Contributor> contributorList = new LinkedList<>();
Collections.sort(contributorList, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return Collator.getInstance().compare(o1, o2);
}
});
Sort using comparator by comparing Contributor objects.
Collections.sort(contributorList, new Comparator<Contributor>() {
@Override
public int compare(Contributor o1, Contributor o2) {
return Collator.getInstance().compare(o1.lastname, o2.lastname);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.