繁体   English   中英

按字符串排序链接列表

[英]Sorting a linked list by string

我正在尝试对链接列表进行排序,并不断获取“找不到适合sort(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);
            }
        });

通过比较贡献者对象,使用比较器进行排序。

Collections.sort(contributorList, new Comparator<Contributor>() {
    @Override
    public int compare(Contributor o1, Contributor o2) {
       return Collator.getInstance().compare(o1.lastname, o2.lastname);
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM