按字符串对链表进行排序
Sorting a linked list by string
我正在尝试对链表进行排序,但一直收到“找不到合适的方法进行排序(LinkedList,>)。我做错了什么?
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);
}
});
通过比较 Contributor 对象使用比较器排序。
Collections.sort(contributorList, new Comparator<Contributor>() {
@Override
public int compare(Contributor o1, Contributor o2) {
return Collator.getInstance().compare(o1.lastname, o2.lastname);
}
});
我正在尝试对链表进行排序,但一直收到“找不到合适的方法进行排序(LinkedList,>)。我做错了什么?
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);
}
});
通过比较 Contributor 对象使用比较器排序。
Collections.sort(contributorList, new Comparator<Contributor>() {
@Override
public int compare(Contributor o1, Contributor o2) {
return Collator.getInstance().compare(o1.lastname, o2.lastname);
}
});